Haskell Understanding Folds
This post is to show a few visuals to help understand foldr and foldl in Haskell.
foldr and foldl using (+). For the (+) function both foldl and foldr are the same, that is because addition is commutative. The ‘0’ after (+) is because the (+) function takes two arguments (+ a b), as such 0 serves as an initial numer to start adding from.
1 2 3 4 5 6 7 

foldr and foldl using (). Subtraction in folds can be a bit harder to imagine without seeing how they expand, but should be easy to understand afterwards.
1 2 3 4 5 6 7 

Another example using a function other than (+), but will expand the same
1 2 3 4 5 6 7 8 
