Difference between revisions of "Monoid"

From HaskellWiki
Jump to navigation Jump to search
(refer to uses)
m (fixed "Arrows, like Monads, are Monoids" link)
(2 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
* numbers under addition or multiplication
 
* numbers under addition or multiplication
 
* Booleans under conjunction or disjunction
 
* Booleans under conjunction or disjunction
* sets under union
+
* sets under union or intersection
 
* functions from a type to itself, under composition
 
* functions from a type to itself, under composition
   
  +
Note that in most of these cases the operation is also commutative, but it need not be; concatenation and function composition are not commutative.
A Monoid class is defined in [http://www.haskell.org/ghc/dist/current/docs/libraries/base/Data-Monoid.html Data.Monoid], and used in [http://www.haskell.org/ghc/dist/current/docs/libraries/base/Data-Foldable.html Data.Foldable] and in the Writer monad.
 
  +
 
A Monoid class is defined in [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Monoid.html Data.Monoid], and used in [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Foldable.html Data.Foldable] and in the Writer monad.
   
 
The monoid interface enables a number of algorithms, including parallel algorithms and tree searches, e.g.:
 
The monoid interface enables a number of algorithms, including parallel algorithms and tree searches, e.g.:
Line 16: Line 18:
   
 
Generalizations of monoids feature in [[Category theory]], for example:
 
Generalizations of monoids feature in [[Category theory]], for example:
* [http://www.cs.ru.nl/~heunen/publications/2006/arrows/arrows.pdf Arrows, like Monads, are Monoids] (PDF)
+
* [http://www.researchgate.net/publication/235540658_Arrows_like_Monads_are_Monoids/file/d912f511ccdf2c1016.pdf Arrows, like Monads, are Monoids] (PDF)

Revision as of 09:41, 18 February 2014

This article is a stub. You can help by expanding it.

A monoid is an algebraic structure with an associative binary operation that has an identity element. Examples include:

  • lists under concatenation
  • numbers under addition or multiplication
  • Booleans under conjunction or disjunction
  • sets under union or intersection
  • functions from a type to itself, under composition

Note that in most of these cases the operation is also commutative, but it need not be; concatenation and function composition are not commutative.

A Monoid class is defined in Data.Monoid, and used in Data.Foldable and in the Writer monad.

The monoid interface enables a number of algorithms, including parallel algorithms and tree searches, e.g.:

Generalizations of monoids feature in Category theory, for example: