foldl f z [1, 2] -- add the array
foldl (-) 0 [1, 2] -- use (-) for f, use 0 for z
((0 `f` 1) `f` 2) -- I left `f` in while thinking about it
((0 `-` 1) `-` 2) -- Written out with `-` as infix
so f is (-)
((0 - 1) - 2) -- written out as a math equation
(-1 - 2) -- reduce it
-3 -- reduce it
fold
reminds me ofreduce
in JavaScript.foldl
&foldr
takeAssocitivity
foldl
is left-associativefoldr
is right-associativeExample
foldl (-) 0 [1, 2]
so f is (-)
Example
foldr f z [...]
Example
foldr (-) 0 [1, 2, 3, 4, 5]