yet another function types syntax variation

Neal Gafter neal at gafter.com
Tue Feb 9 12:17:36 PST 2010


As long as we're throwing our proposals into the ring, here's mine:

*Type*:
    *FunctionType*
*FunctionType*:
    *(** Types*opt *Throws*opt *)* *->* *Type*
*Types*:
    *Type*
    *Types **,* *Type*
*Throws*:
    *throws **QualifiedIdentifierList*

The grammar for ArrayType would be written in such a way that it does not
allow a FunctionType to be the array's element type.

The following syntax for lambdas would not make the result type explicit

*Primary*:
    *StatementLambda*
*Expression*:
    *ExpressionLambda*
*StatementLambda*:
    *FormalParameters **->* *Block*
*ExpressionLambda*
    *FormalParameters **->* *Expression*

For example, here is a currying method:

*static <T,U,V> (T)->(U)->V curry((T,U)->V toCurry) {*
*  return (T t)->(U u)->toCurry.(t, u);*
*}*

That corresponds to the following in the current draft

*static <T,U,V> ##V(U)(T) curry(#V(T,U) toCurry) {*
*  return #(T t)(#(U u)(toCurry.(t, u)));*
*}*

I find the arrow notation far easier to read when composed.  It does
interact a bit strangely with generics, however:

*List<(String)->int> list;*

because the *->* looks, at first glance, as if it is closing the type
argument.  I don't think *#* works as well as the arrow, however

*static <T,U,V> (T)#(U)#V curry((T,U)#V toCurry) {*
*  return (T t)#(U u)#toCurry(t, u);*
*}*
*
*Cheers,
Neal
*
*


More information about the lambda-dev mailing list