## Concept:

# Monad

## Headline

A functional programming idiom for computing effects

## Illustration

The term "monad" originates from category theory, but this illustration focuses on the functional programming view where "monad" refers to a programming idiom for composing computations, specifically computations that may involve side effects or I/O actions. Monads have been popularized by Language:Haskell.

In Haskell, monads are developed and used with the help of the type class *Monad* which is parametrized by a type constructor for the actual monad. Here is a sketch of the type class:

```
class Monad m where
return :: a -> m a
(>>=) :: m a -> (a -> m b) -> m b
(>>) :: m a -> m b -> m b
-- ... some details omitted
```

The *return* function serves the construction of trivial computations, i.e., computations that return values. The *>>=* (also knows as the bind function) compose a computation with a function that consumes the value of said computation to produce a composed computation. Here are some informal descriptions of popular monads:

- State monad
*return*v: return value*v*and pass on state*bind*c f: apply computation*c*as state transformer and pass on transformed state to*f*

- Reader monad
*return*v: return value*v*and ignore environment*bind*c f: pass environment to both*c*and*f*

- Writer monad
*return*v: return value*v*and empty output*bind*c f: compose output from both*c*and*f*

- Maybe monad
*return*v: return "successful" value*v**bind*c f: fail if*c*fails, otherwise, pass on successful result to*f*

## Metadata

- Vocabulary:Functional programming
- Type class
- Programming idiom
- http://www.haskell.org/haskellwiki/Monad
- http://en.wikipedia.org/wiki/Monad_%28functional_programming%29
- http://en.wikipedia.org/wiki/Monad_(category_theory)
- http://en.wikibooks.org/wiki/Haskell/Understanding_monads

## Backlinks

### 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:State monad - 0.5974202
- Concept:Maybe monad - 0.52068126
- Contribution:happstack - 0.5016626
- Concept:Writer monad - 0.45696372
- Concept:Arrow - 0.44666585
- Concept:Monads - 0.41584906
- Concept:Accumulator - 0.37008235
- Concept:Monadic value - 0.36167926
- Script:Monads - 0.3588509
- Technology:Parsec - 0.34729913

## 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.
**