Inferring lambda parameter types in an argument position

Neal Gafter neal at gafter.com
Fri Mar 4 14:18:25 PST 2011


Maurizio-

That's great!  However, I should say I'm more concerned about the
specification than about the current prototype, because

1. The prototype will change, but what we finally get is what we have to
live with;
2. The implementation needs to agree with the specification, not merely
appear to "do the right thing"; and
3. Getting the specification right is much harder, as the spec has to give
some reasonable result in *all* cases, not just the ones that were
encountered while developing the prototype.

Also, there are interesting cases around nested lambdas with overload
resolution that the spec should be capable of handling:

*a.F( x -> x.G( y -> H(x, y) ) )*

That said, I certainly agree that the prototyping effort is helping to
figure out what to specify.

Cheers,
Neal

On Fri, Mar 4, 2011 at 12:11 PM, Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:

> Hi Neal,
> I think we are on the same page here. The current compiler works *almost*
> fine - only problem is inference in chained calls (i.e. chained call to
> 'filter' in your example) - but we are working on it.
>
> Maurizio
>
>
> On 04/03/11 19:16, Neal Gafter wrote:
>
>> interface Mapping<In, Out>
>> {
>>     Out map(In in);
>> }
>> interface IndexedMapping<In, Out>
>> {
>>     Out map(In in, int index);
>> }
>> interface Predicate<E>
>> {
>>     bool isSatisfied(E e);
>> }
>> interface MyList<E>  {
>>     <U>  MyList<U>  map(Mapping<? super E, ? extends U>  f) ...;
>>     <U>  MyList<U>  map(IndexedMapping<? super E, ? extends U>  f) ...;
>>     MyList<E>  filter(Predicate<? super E>  p) ...
>> }
>> *
>>
>> I would like to be able to write my lambdas with parameter types elided:
>> *
>> *
>> *MyList<X>  list = ...;*
>> *MyList<Y>  newList = list
>>     .map( #{ x ->  new Y(x) } )
>>     .filter( #{ y ->  y.IsFunny() } );*
>>
>> This is all modulo syntax.  I'd prefer the syntax
>>
>> *MyList<Y>  newList = list
>>     .map( x ->  new Y(x) )
>>     .filter( y ->  y.IsFunny() );
>> *
>>
>
>


More information about the lambda-dev mailing list