Monad transformer
From Wikipedia, the free encyclopedia
In functional programming, a monad transformer is a type constructor which takes a monad as an argument and returns a monad as a result.
Monad transformers can be used to compose features encapsulated by monads - such as state, exception handling, and I/O - in a modular way. Typically, a monad transformer is created by generalising an existing monad; applying the resulting monad transformer to the identity monad yields a monad which is equivalent to the original monad (ignoring any necessary boxing and unboxing).
Contents |
[edit] Definition
A monad transformer consists of:
- A type constructor
tof kind(* -> *) -> * -> * - Monad operations
returnandbind(or an equivalent formulation) for allt mwheremis a monad, satisfying the monad laws - An additional operation,
lift :: m a -> t m a, satisfying the following laws:[1] (the notation`bind`below indicates infix application):lift . return = returnlift (m `bind` k) = (lift m) `bind` (lift . k)
[edit] Examples
| Please help improve this section by expanding it. Further information might be found on the talk page or at requests for expansion. |
[edit] See also
- Monads in functional programming
- Natural transformation - a related concept in category theory
[edit] References
- ^ Liang, Sheng; Hudak, Paul; Jones, Mark (1995). "Monad transformers and modular interpreters" (PDF). Proceedings of the 22nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages: 333–343, New York, NY: ACM. doi:10.1145/199448.199528.
[edit] External links
- [1] - a highly technical blog post briefly reviewing some of the literature on monad transformers and related concepts, with a focus on categorical-theoretic treatment
| Please help improve this section by expanding it. Further information might be found on the talk page or at requests for expansion. |

