Short syntax
John Nilsson
john at milsson.nu
Sun Dec 27 10:28:52 PST 2009
In most discussions so far the syntax regarding lambdas has all been
explicit.
I.e. #int(int) fun = lambda(int x) (x); from Rémis proposal.
Can we discuss the possibility of a short syntax, using "lifting" and
inferens to produce lambads.
The example above could then be something like
#int(int) fun = x;
or
<T> #T(T) id = x;
In this example x would be treated as a free variable and thus be converted
into an argument to a lambda returning its argument. I imagine that this
particular example might leave to much room for error, but I'm assuming
equally terse, but safer, alternatives could be designed.
Another example
#int(int,int) fun = +;
Here the expression has no free variables but is structurally of the same
type so a simple lifting to a lambda can be performed.
So what do people think is this something worth aiming for?
A more practical use case might be in order. Lets say you need to declare a
projection of some object collection for presentation
List<Invoice> invoices = ...
theObjects.project( .getInvoiceDate(), .getCustomer().getName(),
.getInvoiceNo(), .getInvoiceAmt())
Here I'm using a <T> List<Object[]> project(#Object(T)...projections)
letting the absent object reference signify an argument to the lifted
lambdas.
BR,
John
More information about the lambda-dev
mailing list