Monoid

Monoid 型クラス

class Monoid a where
    mempty  :: a
    mappend :: a -> a -> a

    mconcat :: [a] -> a
    mconcat = foldr mappend mempty

Monoid 則

mempty `mappend` x = x
x `mappend` mempty = x
(x `mappend` y) `mappend` z = x `mappend` (y `mappend` z)
mappend mempty x = x
mappend x mempty = x

mappend (mappend x y) z = mappend x (mappend y z)