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:


There are no revisions for this page.

User contributions

    This user never has never made submissions.

    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.

    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.