A nice way to step into 2012

Jacob Carlborg doob at me.com
Wed Dec 28 08:07:45 PST 2011


On 2011-12-27 15:27, Alex Rønne Petersen wrote:
> On 27-12-2011 15:19, Alex Rønne Petersen wrote:
>> On 27-12-2011 05:25, Andrei Alexandrescu wrote:
>>> https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc
>>>
>>>
>>>
>>>
>>> Andrei
>>
>> Awesome!
>>
>> Now the only gripe I have left is type inference for lambdas passed as
>> regular function parameters. Is this something we will see anytime soon?
>>
>> - Alex
>
> Just to make it clear what I want to be able to do (simple example with
> arrays):
>
> T[] filter(T)(T[] items, scope bool delegate(T) predicate)
> {
> T[] newItems;
>
> foreach (item; items)
> if (predicate(item))
> newItems ~= item;
>
> return newItems;
> }
>
> auto ints = filter([0, 1, 2, 3, 4, 5], x => x % 2 != 0);
>
> Or perhaps even better, when we get fully working UFCS:
>
> auto ints = [0, 1, 2, 3, 4, 5].filter(x => x % 2 != 0);
>
> DMD should be able to infer the parameter type(s) of the delegate I'm
> passing, since that's clear from the array being passed. (I would
> recommend looking at how C#'s type inference rules work; they're quite
> sophisticated for an imperative language.)
>
> - Alex

The type inference in Scala is very powerful as well.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list