Types instantiating Monoid
include lists, numbers, and functions with Monoid
return values, among others. To instantiate Monoid
a type must support an associative binary operation (mappend
or (<>)
) which combines its values, and have a special "zero" value (mempty
) such that combining a value with it does not change that value:
mempty <> x == x
x <> mempty == x
x <> (y <> z) == (x <> y) <> z
Intuitively, Monoid
types are "list-like" in that they support appending values together. Alternatively, Monoid
types can be thought of as sequences of values for which we care about the order but not the grouping. For instance, a binary tree is a Monoid
, but using the Monoid
operations we cannot witness its branching structure, only a traversal of its values (see Foldable
and Traversable
).
mempty :: Monoid m => m
mappend :: Monoid m => m -> m -> m
None