C++11 lambdas

Rémi Forax forax at univ-mlv.fr
Sun Mar 14 09:14:29 PDT 2010


Le 14/03/2010 15:31, Neal Gafter a écrit :
> On Sun, Mar 14, 2010 at 5:21 AM, Stephen Colebourne<scolebourne at joda.org>wrote:
>
>    
>> - no function types
>>
>>      
> Correction: C++ has had function types all along. so it hasn't been
> necessary to add them.  They are invariant.
>
>    

Yes, seeing that I wonder if we are not going in the wrong direction by 
trying
to protect lambda and function type by a # or some enclosing parens.

Why not trying something simpler ?


A function that takes an int and returns an int:
int(int)

A function that takes an int and returns nothing:
void(int)

A function that takes two ints and returns an int:
int(int, int)

A function that throws an Exception:
int(int) throws Exception

A function that takes a function that throws an Exception:
int(int(int) throws Exception)

A function that throws an Exception and takes a function
int(int(int)) throws Exception

A function that takes an int and returns a function that returns an int
int() (int)

curry!
R() throws E (R(A) throws E, A) curry = ...

Grammar:
ResultType ( TypeList ) throws ExceptionList


And removing the # in the lambda syntax:

int(int) fun = (int x) (x);  // lambda expression
int(int) fun = (int x) { return x; };  // lambda block

A method that returns a lambda:
int(int,int) plus() {
   return (int x, int y) (x+y);
}

A method that takes two function types and returns a lambda:
int(int,int) filter(int(int) filter, int(int,int) operation) {
   return (int x, int y) {
     return operation.(filter.(x), filter.(y));
   };
}


Rémi


More information about the lambda-dev mailing list