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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC 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.80.8 with SMTP id n8mr1175318pax.17.1353087896594; Fri, 16 Nov 2012 09:44:56 -0800 (PST) Path: s9ni19992pbb.0!nntp.google.com!news.glorb.com!rt.uk.eu.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Ada202X : Adding functors Date: Fri, 16 Nov 2012 18:44:47 +0100 Organization: cbb software GmbH Message-ID: <1a6o8r3qx00mt.q6xayy8lqwr4$.dlg@40tude.net> References: <0114d327-9f9f-4ad2-9281-56331d11a90c@googlegroups.com> <15w6caje3zsh$.t5nqtwoa77x5$.dlg@40tude.net> <1nns2z6uw5q7m.1vv6s1jevxoqb.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: pSb85Ij4EqcuHDcWtw64BQ.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2012-11-16T18:44:47+01:00 List-Id: On Fri, 16 Nov 2012 07:20:58 -0500, Peter C. Chapin wrote: > 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. It is about how many instances of primitive procedure (X : T) are allowed to exist. It is different from dispatch which selects instances of different functional types. E.g. procedure (X : T) procedure (X : S) S /= T >>> 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 { > // ... > } And the semantics of? Considering this: type T is tagged ... procedure Operation (X : T); procedure Operation_1 (X : T) is new Operation (X : T) with ...; would mean what? >> Override it? > > Not sure what you mean by this. 1. When you inherit from Operation you inherit higher-order functions defined on Operation (not on T). May I override them? 2. Let I inherited from Operation and overrode Operation in T. What happens? 3. The class of operations derived from: procedure (X : T) is procedure (X : T)'Class What is the semantics of? In which relation is it with procedure (X : T'Class) procedure (X : T'Class)'Class >> Which are the classes of types >> >> (Int => Boolean) => String >> >> operates on? > > Scala treats function types as classes with a special 'apply' method. This is equivalent to Ada's access to subprogram. But I suggest that "apply" cannot be overridden just like Ada's all cannot. Which flattens the type structure. The recursion is killed because "apply" or "all" are not really first-class. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de