Tutorial by Topics: monad



A monad is a data type of composable actions. Monad is the class of type constructors whose values represent such actions. Perhaps IO is the most recognizable one: a value of IO a is a "recipe for retrieving an a value from the real world".

We say a type constructor m (such as [] or Maybe) forms a monad if there is an instance Monad m satisfying certain laws about composition of actions. We can then reason about m a as an "action whose result has type a".

State monads are a kind of monad that carry a state that might change during each computation run in the monad. Implementations are usually of the form State s a which represents a computation that carries and potentially modifies a state of type s and produces a result of type a, but the term "state monad" may generally refer to any monad which carries a state. The mtl and transformers package provide general implementations of state monads.

Page 1 of 1