Reified Lambda Functions

Neal Gafter neal at gafter.com
Thu Jan 7 07:56:16 PST 2010


On Thu, Jan 7, 2010 at 3:08 AM, Howard Lovatt <howard.lovatt at iee.org> wrote:
> I have posted a *more* formal proposal for reifying lambdas (as suggested by
> Neal Gafter):
> http://www.artima.com/weblogs/viewpost.jsp?thread=278567
> This could be read in conjunction with the original informal proposal:
> http://www.artima.com/weblogs/viewpost.jsp?thread=277879
> Which is an easier read :)

Having looked at these, most of what was unclear to me before is still
unclear.  I still don't know *when* this specification requires the
conversions via the "From" classes, and when it doesn't.  The
description is too informal to intuitively map to a specification.

Back to my last example, I still do not see how this specification handles it:

Consider a method that returns a generic list of functions:

<T> List<#T()> lazify(List<T> data) {
    List<#T()> result = new ArrayList<#T()>();
    for (T t : data) result.add(#()t); // adds element of type Callable$0<T>
    return result;
}

the list that is returned contains lambdas of type Callable$0<T>.
Then we call it on some data

List<#String()> alphabet() {
    return lazify(Arrays.asList("a", "b", "c"));
}
List<#String()> alphabet = alphabet();

now alphabet contains a List whose elements are of type
Callable$0<String> (but the compiler probably thinks those elements
are of type Callable$String).  So we pull a datum out of it.

#String() firstLetter = alphabet.get(0);

Now we've assigned something of type Callable$0<String> to something
of type Callable$String.  Where in the execution of this code did the
"cast" occur?


More information about the lambda-dev mailing list