Anonymous function syntax

bearophile bearophileHUGS at lycos.com
Wed Sep 21 15:29:34 PDT 2011


Walter Bright:

> D
>      (a,b) { return a + b; }

In D to define a true lambda you need types too:
auto f = (int a,int b){ return a + b; };

For D I think I'd like a syntax like:
{ int a, int b => a + b }
That in some cases becomes just:
{ a,b => a + b }


> Haskell
>      \a b -> a + b

In Haskell you often don't use lambdas. You curry functions, or your use already written little higher order functions/operators to build something, or sometimes you use list comprehensions:

http://www.haskell.org/haskellwiki/List_comprehension
take 10 [ (i,j) | i <- [1..], let k = i*i, j <- [1..k]]

In Python too you often use list comprehensions instead of lambdas + filter + map.

Bye,
bearophile


More information about the Digitalmars-d mailing list