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
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
State s awhich represents a computation that carries and potentially modifies a state of type
sand produces a result of type
a, but the term "state monad" may generally refer to any monad which carries a state. The
transformerspackage provide general implementations of state monads.