"fold": a replacement for "reduce"

Timon Gehr timon.gehr at gmx.ch
Fri Mar 28 15:39:24 PDT 2014


On 03/28/2014 01:41 AM, Meta wrote:
> On Thursday, 27 March 2014 at 22:33:50 UTC, Timon Gehr wrote:
>> It doesn't make sense at all. It is an arbitrary limitation. The rule
>> is simple though: One can only alias things that syntactically look
>> like they might be types. This is why the following triviality is way
>> more useful than it should be:
>>
>> alias Id(alias a)=a;
>>
>> alias fun = Id!(a=>a); // ok!
>
> You can tell me that function literals look like types, but I won't
> believe you.

You mean because the literal is accepted as an alias argument? Alias 
template arguments are not actually the same thing as alias 
declarations. (Eg. the latter can accept built-in types like 'int', 
while the former will not, but otherwise allow arbitrary expressions.) I 
used to think this was a bug, but Walter stated that this is in fact by 
design. (I think this is a gratuitous design mistake.)

The expressions that are used in alias declarations are 'a' and 
'Id!(a=>a)'. Both of those can occur in a context where they denote types.


More information about the Digitalmars-d mailing list