A syntax option (function types versus arrays)
Howard Lovatt
howard.lovatt at gmail.com
Wed Mar 10 22:08:17 PST 2010
There has been a long discussion about the syntax for lambdas and no
solution has been found, this was expressed nicely by Josh Bloch:
> I agree that it would be nice if we had something that nests better, and I'm
> totally open to suggestion. But this alternative comes with many downsides:
> surrounding a type in parens might appear tempting, but it really looks like
> a cast to current-day Java programmers. As per my previous e-mail, I'm all
> about designing a facility that is maximally readable, familiar, and
> non-threatening to current-day Java programmers.
Also the distinction between the lambda type and the lambda isn't
clear (I think that both Rémi Forax and Reinier Zwitserloot have
raised this issue - though you can't search Lambda Dev so I can't be
certain it was them!).
A possible alternate syntax is:
#< R( A ) throws E > example = new #< R( A a ) throws E >( ... );
This syntax is in keeping with current Java, e.g.:
#< R( A ) throws E > example = new #< R( A a ) throws E >( ... );
ArrayList< Integer > aList = new ArrayList< Integer >();
You can have arrays:
#< R( A ) throws E >[] array = new #< R( A ) throws E >[ 1 ];
You can nest lambdas:
#< #< R() throws E >( #< R( A ) throws E >, A ) > curry = new #< #<
R() throws E >( #< R( A ) throws E > l, A a ) >( l.( a ) );
The two specific suggestions embodied in the examples above are:
1. Mimic the method declaration syntax minus the method name, like the
current proposal does, but enclose that within angle brackets, to
mimic a generic declaration.
2. Require new to be used when you create a Lambda, to mimic current
Java declarations and to clearly distinguish between the type and the
creation.
Comments?
-- Howard.
More information about the lambda-dev
mailing list