## Concept:

# Monoid

## Headline

A type with an associative operation and a neutral element

## Illustration

The notion of monoid is precisely defined in group theory, but we focus here on its illustration in a programming setting. Specifically, in functional programming, a monoid is essentially a type with an associative operation and a neutral element. For instance, lists form a monoid with the empty list as neutral element and list append as the associative operation. Monoids are useful, for example, in aggregating results.

In Language:Haskell, monoids are modeled through the type class *Monoid* with first two members needed for a minimal complete definition:

```
-- The type class Monoid
class Monoid a
where
mempty :: a -- neutral element
mappend :: a -> a -> a -- associative operation
mconcat :: [a] -> a -- fold
mconcat = foldr mappend mempty
```

Algebraically, the following properties are required for any monoid (given in Haskell notation):

```
mempty `mappend` x = x -- left unit
x `mappend` mempty = x -- right unit
x `mappend` (y `mappend` z) = (x `mappend` y) `mappend` z -- associativity
```

See the following monoids for continued illustration:

## Metadata

- Data type
- Vocabulary:Functional programming
- Vocabulary:Mathematics
- http://en.wikipedia.org/wiki/Monoid
- http://mathworld.wolfram.com/Monoid.html
- http://en.wikibooks.org/wiki/Haskell/Monoids
- http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Monoid.html

### There are no revisions for this page.

## User contributions

## User edits

## Syntax for editing wiki

For you are available next options:will make text bold.

will make text italic.

will make text underlined.

will make text striked.

will allow you to paste code headline into the page.

will allow you to link into the page.

will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

will allow you to paste image into the page.

is list with bullets.

is list with numbers.

will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

will allow your to insert code snippets from
**
@worker.
**

#### 10 most similar pages:

- Concept:List monoid - 1.7032522
- Concept:Sum monoid - 1.3965578
- Concept:Foldable type - 1.0403734
- Concept:Fold_function - 0.7934468
- Technology:QuickCheck - 0.7064987
- Concept:Type class - 0.6155632
- Concept:Writer monad - 0.5339345
- Concept:Applicative functor - 0.51923996
- Concept:List comprehension - 0.51826257
- Concept:Polymorphism - 0.49505484

## Syntax for editing wiki

For you are available next options:will make text bold.

will make text italic.

will make text underlined.

will make text striked.

will allow you to paste code headline into the page.

will allow you to link into the page.

will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

will allow you to paste image into the page.

is list with bullets.

is list with numbers.

will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

will allow your to insert code snippets from
**
@worker.
**