"fold": a replacement for "reduce"

Simen Kjærås simen.kjaras at gmail.com
Thu Mar 27 08:54:08 PDT 2014


On 2014-03-27 14:45, monarch_dodra wrote:
> On Thursday, 27 March 2014 at 14:41:19 UTC, Brian Rogoff wrote:
>> On Thursday, 27 March 2014 at 13:23:27 UTC, monarch_dodra wrote:
>>> On Thursday, 27 March 2014 at 12:48:41 UTC, Simen Kjærås wrote:
>>>> Your new fold (foldl? Should we have foldr as well?)
>>>
>>> "fold" (from what I understood) is what you call "foldl". It was
>>> discussed to not introduce "foldr", as it's just
>>> "fold!(binaryReverseArgs!Fun)(range.retro);".
>>>
>>> I'm not sure I was able to understand what the difference between
>>> "fold" and "foldl" is...
>>
>> In functional languages,
>>
>> fold_left(f, a, [b1, ..., bn]) is
>> f((... (f, (f, a, b1), b2) ...), bn)
>>
>> as you can see, the innermost f call is on the leftmost sequence
>> element, and
>>
>> fold_right(f, [a1, ..., an], b) is
>> f(a1, (f a2 (... f(an, b) ...)))
>>
>> That's how I think of them.
>
> Right, but what about "fold" vs "fold_left"? Is there a difference?

Different languages may have different standards, but I think fold is 
usually a left fold. So, no difference.

--
   Simen


More information about the Digitalmars-d mailing list