Foldr and Foldl in Haskell
This blog introduces how foldr
and foldl
work for a better usage them. Understanding the accumulation and association support from them is crucial.
foldr: Right-associative fold of a structure, lazy in the accumulator.
foldl: Left-associative fold of a structure, lazy in the accumulator.
In short, it helps you to construct a left/right associative structure. One of the real cases is you want to construct a left associative structure inside a parser , but you parse it in a right recursive way.
Note that this is a simple note, which has been already covered by documentation, and I wrote it because at the beginning I misunderstand its feature, so I wrote some code to try.