UP | HOME

monoid (haskell)

1. definition

First look at the semigroup type class (see Typeclasses in Haskell for more information)

class Semigroup a where
   (<>) :: a -> a -> a

The prefix version of (<>) is called mappend.

Then, the monoid type class is:

class Semigroup a => Monoid a where
mempty :: a

A monoid is a semigroup with an identity element.

2. example

import Data.Monoid
getSum $ Sum 1 <> Sum 2

foldable and traversable (haskell)

3. see also

  • In algebra, a monoid is a set with an identity element and an associative operation that is closed. (see group (algebra))

4. sources

Created: 2024-07-15 Mon 01:28