Folds, maps, and filters

Why use folds, maps, and filters?

A quick glance reveals that adler32_foldl isn’t really any shorter than adler32_try2. Why should we use a fold in this case? The advantage here lies in the fact that folds are extremely common in Haskell, and they have regular, predictable behavior.

This means that a reader with a little experience will have an easier time understanding a use of a fold than code that uses explicit recursion. A fold isn’t going to produce any surprises, but the behavior of a function that recurses explicitly isn’t immediately obvious.

— Chapter 4: Functional programming

— Real World Haskell

— by Bryan O’Sullivan, Don Stewart, and John Goerzen

2012.05.20 Sunday ACHK