Left-associative fold of a structure.
In the case of lists,
foldl, when applied to a binary operator,
a starting value (typically the left-identity of the operator), and a
list, reduces the list using the binary operator, from left to right:
foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn
Note that to produce the outermost application of the operator the
entire input list must be traversed. This means that
foldl'
will diverge if given an infinite list.
Also note that if you want an efficient left-fold, you probably want
to use
foldl' instead of
foldl. The reason for this is
that latter does not force the "inner" results (e.g.
z `f` x1
in the above example) before applying them to the operator (e.g. to
(`f` x2)). This results in a thunk chain <math>
elements long, which then must be evaluated from the outside-in.
For a general
Foldable structure this should be semantically
identical to,
foldl f z = foldl f z . toList