Daniel Wagner on 12 Sep 2011 06:54:30 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Announcing Functional Fall: A 6-session functional programming reading circle in the Fall


Jim Snavely wrote:
> This is rather confusing, because our notions of "to the left" and "to
> the right" are ambiguous.

For what it's worth, I remember which is which by associativity.
foldr's function argument is right-associated in the expansion:

foldr f z [a,b,c] = a `f` (b `f` (c `f` z))
{ when f is infixr } = a `f` b `f` c `f` z

Whereas foldl's function argument is left-associated in the expansion:

foldl f z [a,b,c] = ((z `f` a) `f` b) `f` c
{when f is infixl } = z `f` a `f` b `f` c

~d