Given any monad
, the option monad transformer
(where
denotes the option type) is defined by:
- :&A\rightarrow \mathrm {M} \left(A^{?}\right)\\&a\mapsto \mathrm {return} (\mathrm {Just} \,a)\\\mathrm {bind} :&\mathrm {M} \left(A^{?}\right)\rightarrow \left(A\rightarrow \mathrm {M} \left(B^{?}\right)\right)\rightarrow \mathrm {M} \left(B^{?}\right)\\&m\mapsto f\mapsto \mathrm {bind} \,m\,\left(a\mapsto {\begin{cases}{\mbox{return Nothing}}&{\mbox{if }}a=\mathrm {Nothing} \\f\,a'&{\mbox{if }}a=\mathrm {Just} \,a'\end{cases}}\right)\\\mathrm {lift} :&\mathrm {M} (A)\rightarrow \mathrm {M} \left(A^{?}\right)\\&m\mapsto \mathrm {bind} \,m\,(a\mapsto \mathrm {return} (\mathrm {Just} \,a))\end{array}}}

Given any monad
, the exception monad transformer
(where E is the type of exceptions) is defined by:
- :&A\rightarrow \mathrm {M} (A+E)\\&a\mapsto \mathrm {return} (\mathrm {value} \,a)\\\mathrm {bind} :&\mathrm {M} (A+E)\rightarrow (A\rightarrow \mathrm {M} (B+E))\rightarrow \mathrm {M} (B+E)\\&m\mapsto f\mapsto \mathrm {bind} \,m\,\left(a\mapsto {\begin{cases}{\mbox{return err }}e&{\mbox{if }}a=\mathrm {err} \,e\\f\,a'&{\mbox{if }}a=\mathrm {value} \,a'\end{cases}}\right)\\\mathrm {lift} :&\mathrm {M} \,A\rightarrow \mathrm {M} (A+E)\\&m\mapsto \mathrm {bind} \,m\,(a\mapsto \mathrm {return} (\mathrm {value} \,a))\\\end{array}}}

Given any monad
, the reader monad transformer
(where E is the environment type) is defined by:
- :&A\rightarrow E\rightarrow \mathrm {M} \,A\\&a\mapsto e\mapsto \mathrm {return} \,a\\\mathrm {bind} :&(E\rightarrow \mathrm {M} \,A)\rightarrow (A\rightarrow E\rightarrow \mathrm {M} \,B)\rightarrow E\rightarrow \mathrm {M} \,B\\&m\mapsto k\mapsto e\mapsto \mathrm {bind} \,(m\,e)\,(a\mapsto k\,a\,e)\\\mathrm {lift} :&\mathrm {M} \,A\rightarrow E\rightarrow \mathrm {M} \,A\\&a\mapsto e\mapsto a\\\end{array}}}

Given any monad
, the state monad transformer
(where S is the state type) is defined by:
- :&A\rightarrow S\rightarrow \mathrm {M} (A\times S)\\&a\mapsto s\mapsto \mathrm {return} \,(a,s)\\\mathrm {bind} :&(S\rightarrow \mathrm {M} (A\times S))\rightarrow (A\rightarrow S\rightarrow \mathrm {M} (B\times S))\rightarrow S\rightarrow \mathrm {M} (B\times S)\\&m\mapsto k\mapsto s\mapsto \mathrm {bind} \,(m\,s)\,((a,s')\mapsto k\,a\,s')\\\mathrm {lift} :&\mathrm {M} \,A\rightarrow S\rightarrow \mathrm {M} (A\times S)\\&m\mapsto s\mapsto \mathrm {bind} \,m\,(a\mapsto \mathrm {return} \,(a,s))\end{array}}}

Given any monad
, the writer monad transformer
(where W is endowed with a monoid operation ∗ with identity element
) is defined by:
- :&A\rightarrow \mathrm {M} (W\times A)\\&a\mapsto \mathrm {return} \,(\varepsilon ,a)\\\mathrm {bind} :&\mathrm {M} (W\times A)\rightarrow (A\rightarrow \mathrm {M} (W\times B))\rightarrow \mathrm {M} (W\times B)\\&m\mapsto f\mapsto \mathrm {bind} \,m\,((w,a)\mapsto \mathrm {bind} \,(f\,a)\,((w',b)\mapsto \mathrm {return} \,(w*w',b)))\\\mathrm {lift} :&\mathrm {M} \,A\rightarrow \mathrm {M} (W\times A)\\&m\mapsto \mathrm {bind} \,m\,(a\mapsto \mathrm {return} \,(\varepsilon ,a))\\\end{array}}}

Given any monad
, the continuation monad transformer maps an arbitrary type R into functions of type
, where R is the result type of the continuation. It is defined by:

Note that monad transformations are usually not commutative: for instance, applying the state transformer to the option monad yields a type
(a computation which may fail and yield no final state), whereas the converse transformation has type
(a computation which yields a final state and an optional return value).