3 ms·
It's useful when you write functions that take generic monoids as arguments, such as many aggregation functions on data structures. For instance, finding the la
by chas 9y ago
It's useful when you write functions that take generic monoids as arguments, such as many aggregation functions on data structures. For instance, finding the largest element in a tree, or the first successful result in a list of actions. Structuring the code like this separates the concerns of traversing the data structure and performing the particular type of aggregation. Haskell has the function foldMap which implements this idea.
If this is interesting to you Dan Piponi goes into significantly more detail (http://blog.sigfpe.com/2009/01/haskell-monoids-and-their-uses.html http://blog.sigfpe.com/2009/01/haskell-monoids-and-their-use...).