Undefined Title

foldr and foldl of Haskell

2013-01-14

A difference of foldr and foldl.

$ ghci
GHCi, version 7.4.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> foldl (-) 1 [2,3,4]
-8
Prelude> foldr (-) 1 [2,3,4]
2
Prelude> 

It’s easy to understand as thinking like:

foldl calculates ((0 - 1) - 2) - 3.
foldr does 3 - (2 - (1 - 0)).