Differences between `foldl` and `foldr`

31 points by eatonphil


ryan-duve

TIL what a thunk is.


The article starts with:

To start, you have to understand that foldl and foldr are not folds “from the left” and “from the right.” Both foldl and foldr traverse the structure in the same order, which in the case of lists means left to right. The difference is the fold’s associativity.

but then goes on to explain that the list is processed exactly as if the right two items are processed first, then continuing to proceed right-to-left. The whole thing seems to me like an explanation of how the internal workings of lazy vs eager implementations affect performance, but I can't distinguish the final result from

foldl and foldr fold “from the left” and “from the right exactly as you expect. That may be bad performancewise.