Monoids
Overview
Monoids play quite a prominent role in Haskell.
From Data.Monoid:
code:monoidClass.hs
class Monoid a where
mempty :: a
mappend :: a -> a -> a
mconcat :: a -> a -- = foldr mappend mempty (<>) :: Monoid a => a -> a -> a
(<>) = mappend
The first function is mempty. mempty represents the identity value for a particular monoid.
mappend, takes two values of the same type and returns a value of that type as well.
Monoid laws
code:monoidlaw.hs
mempty mappend x = x
x mappend mempty = x
(x mappend y) mappend z = x mappend (y mappend z)
Useful links