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.79.105 with SMTP id i9mr655009pax.34.1353024934418; Thu, 15 Nov 2012 16:15:34 -0800 (PST) Path: s9ni18236pbb.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: Thu, 15 Nov 2012 18:15:33 -0600 Date: Thu, 15 Nov 2012 19:15:33 -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> <50a5492c$0$9523$9b4e6d93@newsspool1.arcor-online.net> In-Reply-To: Message-ID: X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-5qAu0RtU4NE7iM8fTHQsyWUrb/glmIsY2VJVPJU+Iom8bHx8LEQ365e3Jn8pSkl4jUQLmdU4nlwWwSQ!HlEgKU+dgXunhZpoIKFKufI002H7pGV7JkNHdaMCcrHr0cptLaBN0D+GOG+yNsE= 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: 2810 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-11-15T19:15:33-05:00 List-Id: On 11/15/2012 03:39 PM, Dmitry A. Kazakov wrote: > It boils down to weak typing because a closure is not considered > implementation of some stated, well-thought, designed type property. It is > written ad hoc. The design is in the higher order function you are using. My example of 'filter' again: def filter(someList: List[Int], predicate: Int => Boolean) = ... I'll send that function a closure val resultList = filter(myList, item => item % 2 == 0) Here 'item => item % 2 == 0' is a function taking the parameter 'item' and returning true if it is evenly divisible by two. The compiler knows the type of 'item' is Int because it is used in a context where an expression of type Int => Boolean is expected. The author of 'filter' conducted the well-thought design here. The compiler verifies that 'item % 2 == 0' is type correct and evaluates to the required type (Boolean in this case). In this case filter would select items from myList that are even and return them in a new list. This could be done with a loop, of course, but that would require mutable state and would arguably be less clear. Of course that's a matter of taste. Peter P.S. Scala actually allows you to write closures with a special abbreviation in some cases. The expression above would really be val resultList = filter(myList, _ % 2 == 0)