"fold": a replacement for "reduce"

monarch_dodra monarchdodra at gmail.com
Fri Mar 28 04:06:29 PDT 2014


On Thursday, 27 March 2014 at 22:29:01 UTC, Timon Gehr wrote:
> On 03/27/2014 03:45 PM, monarch_dodra wrote:
>>
>> Right, but what about "fold" vs "fold_left"? Is there a 
>> difference?
>
> 'fold' is not descriptive enough. Ranges/lists have a very 
> particular structure allowing 'foldl' to make sense. In general 
> recursive data types (eg. think binary tree) allow only one 
> fold (the recursive one). The instantiation for lists is 
> 'foldr'.
>
> I'd rather have this named 'foldl'. 'fold' is a more abstract 
> name 'foldr' rather than 'foldl'.

That makes sense.

Would it make sense to have also have a "fold" that does 
recursive reduction? EG:

fun(fun(a[0], a[1]), fun(a[2], a[3]))

That could seem useful to me.


More information about the Digitalmars-d mailing list