为什么累加器AccIn
不是左参数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()
我问这个是因为几乎所有其他函数式语言(例如haskell
, scala
)都反过来。您的意思是将左折叠可视化为从左侧累积
foldl f z [x1, x2, ..] = ((z f x1) f x2) ..