Why is the accumulator AccIn
not the left parameter for Fun
?
http://erlang.org/doc/man/lists.html#foldl-3
foldl(Fun, Acc0, List) -> Acc1
Fun = fun((Elem :: T, AccIn) -> AccOut)
Acc0 = Acc1 = AccIn = AccOut = term()
List = [T]
T = term()
I ask this because nearly every other functional language (e.g. haskell
, scala
) has it the the other way round. You're meant to visualize a left fold as accumulating from the left as
foldl f z [x1, x2, ..] = ((z f x1) f x2) ..