Wanted: overloading use cases

Remi Forax forax at univ-mlv.fr
Thu Oct 11 00:15:28 PDT 2012


On 10/11/2012 01:23 AM, Dan Smith wrote:
> On Oct 10, 2012, at 5:07 PM, Remi Forax <forax at univ-mlv.fr> wrote:
>
>> On 10/11/2012 12:48 AM, Dan Smith wrote:
>>> I've recently been exploring and refining our overload resolution algorithm for Lambda.  I'm looking for some real-world examples of Lambda code that we should support.  If you have experience with a library that makes use of lambda-like features (in any language, or a Java library that could naturally be enhanced with lambda support), please read on!
>>>
>>> A typical challenging use case for overload resolution looks like this:
>>>
>>> interface Stream<E> {
>>>   <R> Stream<R> map(Mapper<E, R> m);
>>>   IntStream map(IntMapper<E> m);
>>>   LongStream map(LongMapper<E> m);
>>> }
>>>
>>> Stream<Foo> s = ...;
>>> s.map(f -> f.method());
>> I hope this example calls map(IntMapper).
> Depends on the declaration of 'Foo'. :-)
>
> Yes, if the lambda body produces an int (or short, or byte) the IntMapper one would be preferred over the other two.

Yes, right,
I was thinking about:

   Stream<Integer> s = ...;
   s.map(f -> f.method());



>
>>> Notable properties of this example:
>>> 1) There are multiple methods of the same arity, differing in a functional interface parameter type
>>> 2) The arities of the corresponding functional interfaces are identical
>>> 3) No non-lambda argument can be used for disambiguation
>>> 4) The functional interfaces have the same parameter type(s)
>> I don't understand, 1 and 4 are contradictory, no ?
> Yes, I was a bit unclear.  The _overloaded methods_ have different parameter types (e.g., IntMapper vs. LongMapper).  The _functional interface methods_ have the same parameter types (e.g., E).
>
> (1) might have been better stated as "differing in a parameter type that is a different functional interface for each method", or something like that.

still not that clear because Mapper has two parameter types, E and R.

>
> —Dan

Rémi



More information about the lambda-dev mailing list