From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FORGED_MUA_MOZILLA,FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2078ce7aac45af5b X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.66.85.133 with SMTP id h5mr931823paz.23.1353068459540; Fri, 16 Nov 2012 04:20:59 -0800 (PST) Path: s9ni19583pbb.0!nntp.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 16 Nov 2012 06:20:59 -0600 Date: Fri, 16 Nov 2012 07:20:58 -0500 From: "Peter C. Chapin" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121028 Thunderbird/16.0.2 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada202X : Adding functors References: <0114d327-9f9f-4ad2-9281-56331d11a90c@googlegroups.com> <15w6caje3zsh$.t5nqtwoa77x5$.dlg@40tude.net> <1nns2z6uw5q7m.1vv6s1jevxoqb.dlg@40tude.net> In-Reply-To: <1nns2z6uw5q7m.1vv6s1jevxoqb.dlg@40tude.net> Message-ID: X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-q1y+SMAtEl5sb+Zsm/AnTwV2zt9aPOJLj4TJSreeGuGXs/ZSX9ADAqQ7M/0rXRhEhcl1RlUXCKmmdSZ!4cT8nIi5Meq/BsNcxMuzFNJo+VlQRijj44jMb1VliDEKsUn6hJMNL0c++XIdlHU= X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3396 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-11-16T07:20:58-05:00 List-Id: On 11/16/2012 03:59 AM, Dmitry A. Kazakov wrote: > type T is tagged ... > procedure Operation (X : T); > > There is only one instance of Operation for T. This is easy when Operation > is not an object. Once you make it an object, there could possibly be more > than one instance of. > > X : T'Class; > begin > X.Operation; -- Which one instance is called here? Isn't this an issue even without first class functions? It sounds like you are talking about dynamic dispatch... an OOP issue, not a functional issue. I guess I'm still not following you. >> def filter(someList: List[Int], predicate: Int => Boolean) = ... >> >> This defines a function 'filter' that takes a list of integers and a >> function from Int to Boolean. The notation 'Int => Boolean' is a >> function type. And yes, you can write types like >> >> (Int => Boolean) => String >> >> for functions taking a (function from Int to Boolean) and returning >> String. It's no big deal. > > Can I inherit it? Yes. class MyClass extends (Int => Boolean) => String { // ... } > Override it? Not sure what you mean by this. You can override what it does when applied to an argument. > Which are the classes of types > > (Int => Boolean) => String > > operates on? Scala treats function types as classes with a special 'apply' method. While that might seem like a circular definition it isn't because methods and functions are regarded differently in that language. In particular the type (Int => Boolean) => String is syntactic sugar for Function1[Function1[Int, Boolean], String] where the [] syntax is used for generic type parameters. Anyway Scala has unusually tight integration between its functional and object oriented features (which is why I was surprised to learn that it didn't support contravariant refinement of parameter types). It's one of the hallmarks of that particular language. Peter