Does D have too many features?

Timon Gehr timon.gehr at gmx.ch
Mon Apr 30 12:08:18 PDT 2012


On 04/30/2012 05:13 PM, Alex Rønne Petersen wrote:
> On 30-04-2012 12:18, foobar wrote:
>> Meta comment: C++ is the spawn of the devil so I don't accept anything
>> related to c++ as a valid argument.
>>
>> On Sunday, 29 April 2012 at 20:09:34 UTC, Alex Rønne Petersen wrote:
>> [...]
>>>>
>>>> I have used D and didn't claim that foreach isn't useful.
>>>> What I said that is that it belongs in the library, NOT the language.
>>>
>>> Yeah, we tried that in C++. It sucked.
>>
>> See meta comment above.
>>
>>>
>>> The reason it works for many functional languages is that they have
>>> even more terse syntax than D. It would suck to make foreach a
>>> function in D.
>>>
>>
>> D wants to support functional programming. That means we should provide
>> whatever is necessary to write functional style code including foreach
>> methods. IF D can't properly implement a FP foreach method (And IMO it
>> *can*) than we have failed.
>
> Of course it can, but not with type inference, unless you templatize it.
> That is:
>
> void forEach(alias fun, R)(R range)
> {
> // ...
> }
>
> enjoys type inference: forEach!(item => foo(item))(myRange);
>
> But this doesn't:
>
> void forEach(R)(R range, scope void delegate(ElementType!R) dg)
> {
> // ...
> }
>
> This won't work: forEach(myRange, item => foo(item));
>
> You have to do: forEach(myRange, (ElementType!(typeof(myRange)) =>
> foo(item));
>
> which, frankly, sucks.
>

I agree. It is due to the fact that currently actually no inference 
takes place, it is just simple deduction. It shouldn't be very hard to 
add that functionality.



More information about the Digitalmars-d mailing list