[squeak-dev] Re: Collection>>sum implementation

Jason Johnson jason.johnson.081 at gmail.com
Tue Aug 12 12:52:17 UTC 2008


On Tue, Aug 12, 2008 at 11:21 AM, Tony Garnock-Jones <tonyg at lshift.net> wrote:
> Jason Johnson wrote:
>>
>> #inject:into: behaves like a right fold (reduction moves from left to
>> right) but with the [] on the front of the list instead of the end.
>
> It's actually behaving like a *left* fold. The leftness/rightness of a fold
> is named after the left/right associativity that the combining operator is
> given -- the difference between
>
>  ((([] : 1) : 2) : 3)       -- a left fold, with (:) invoked
>                             -- left-associatively
>
> and
>
>  (1 : (2 : (3 : [])))       -- a right fold, with (:) invoked
>                             -- right-associatively
>
> In haskell,
>
>  foldr (:) [] =~= id
>
> and
>
>  foldl (flip (:)) [] === reverse
>
> Regards,
>  Tony

Ah right, left is the one that can work on infinite sets (in Haskell
at least).  The diagram I looked at before I sent this message
appeared to have right fold mean the computation moves from left to
right.



More information about the Squeak-dev mailing list