Table of Contents

Folds

foldr foldl
right fold left fold
can deal with infinite lists can only deal with finite lists
(lazy) (strict)
needs more heap space needs more stack space
can lead to stack overflows
efficiently compiled as a loop
slower fast
initial value is used when one reaches the end of the list initial value combined with the first element of the list
immediately returns if f does not demand the rest of the recursion immediately calls itself with new parameters until it reaches the end of the list
order is kept order is reverse
type: Foldable t ⇒ (a → b → b) → b → t a → b type: Foldable t ⇒ (b → a → b) → b → t a → b
Note the order in underlined function.
variants with single quote (“'”) as postfix variants with one (“1”) as postfix
foldl' , foldl1' foldl1, foldl1' , foldr1
stricter variant no initial value as parameter
forces the evaluation of the initial parameter before making the recursive call initial value is last and first element of the list, respectively

foldr

foldl

foldl'

Order of execution

The implications regarding order of execution:

Keeping order and beeing fast?

Conclusion and selection