Identity The
identity functor on a category C is a monad. Its multiplication and unit are the
identity function on the objects of C.
Monads arising from adjunctions Any
adjunction :F: C \rightleftarrows D : G gives rise to a monad on
C. This very widespread construction works as follows: the endofunctor is the composite :T = G \circ F. This endofunctor is quickly seen to be a monad, where the unit map stems from the unit map \operatorname{id}_C \to G \circ F of the adjunction, and the multiplication map is constructed using the counit map of the adjunction: :T^2 = G \circ F \circ G \circ F \xrightarrow{G \circ \text{counit} \circ F} G \circ F = T. In fact,
any monad can be found as an explicit adjunction of functors using the
Eilenberg–Moore category C^T (the category of T-algebras).
Double dualization The
double dualization monad, for a fixed
field k arises from the adjunction :(-)^* : \mathbf{Vect}_k \rightleftarrows \mathbf{Vect}_k^{op} : (-)^* where both functors are given by sending a
vector space V to its
dual vector space V^* := \operatorname{Hom}(V, k). The associated monad sends a vector space
V to its
double dual V^{**}. This monad is discussed, in much greater generality, by .
Closure operators on partially ordered sets For categories arising from
partially ordered sets (P, \le) (with a single morphism from x to y
if and only if x \le y), then the formalism becomes much simpler: adjoint pairs are
Galois connections and monads are
closure operators.
Free-forgetful adjunctions For example, let G be the
forgetful functor from
the category Grp of
groups to the
category Set of sets, and let F be the
free group functor from the category of sets to the category of groups. Then F is left adjoint of G. In this case, the associated monad T = G \circ F takes a set X and returns the underlying set of the free group \mathrm{Free}(X). The unit map of this monad is given by the maps :X \to T(X) including any set X into the set \mathrm{Free}(X) in the natural way, as strings of length 1. Further, the multiplication of this monad is the map :T(T(X)) \to T(X) made out of a natural
concatenation or 'flattening' of 'strings of strings'. This amounts to two
natural transformations. The preceding example about free groups can be generalized to any type of algebra in the sense of a
variety of algebras in
universal algebra. Thus, every such type of algebra gives rise to a monad on the category of sets. Importantly, the algebra type can be recovered from the monad (as the category of Eilenberg–Moore algebras), so monads can also be seen as generalizing varieties of universal algebras. Another monad arising from an adjunction is when T is the endofunctor on the category of vector spaces which maps a vector space V to its
tensor algebra T(V), and which maps linear maps to their tensor product. We then have a natural transformation corresponding to the embedding of V into its
tensor algebra, and a natural transformation corresponding to the map from T(T(V)) to T(V) obtained by simply expanding all tensor products.
Codensity monads Under mild conditions, functors not admitting a left adjoint also give rise to a monad, the so-called
codensity monad. For example, the inclusion :\mathbf{FinSet} \subset \mathbf{Set} does not admit a left adjoint. Its codensity monad is the monad on sets sending any set
X to the set of
ultrafilters on
X. This and similar examples are discussed in .
Monads used in denotational semantics The following monads over the category of sets are used in
denotational semantics of
imperative programming languages, and analogous constructions are used in functional programming.
The maybe monad The endofunctor of the
maybe or
partiality monad adds a disjoint point: :(-)_{*}: \mathbf{Set}\to\mathbf{Set} :X\mapsto X\cup\{*\} The unit is given by the inclusion of a set X into X_*: :\eta_X: X\to X_{*} :x\mapsto x The multiplication maps elements of X to themselves, and the two disjoint points in (X_{*})_{*} to the one in X_{*}. In both functional programming and denotational semantics, the maybe monad models
partial computations, that is, computations that may fail.
The state monad Given a set S, the endofunctor of the
state monad maps each set X to the set of functions S\to S \times X. That is S(X) = \{f:S\to S\times X\}, and S(S(X)) = \{f:S\to S\times (S\to S\times X)\}. The component of the unit at X maps each element x\in X to the function :\eta_X(x): S\to S\times X :s\mapsto (s, x) The multiplication maps the function f: S\to S\times (S\to S\times X), s\mapsto (s',f') to the function :\mu_X(f): S\to S\times X :s\mapsto f'(s') In more detail, given f\in S(S(X)) which is the pair f=(f_1,f_2) where f_1:S\to S and f_2: S \to (S \to S\times X), so that f(s) = \big(f_1(s),f_2(s):S\to (S\times X)\big). We can reverse Curry f_2 to give f_3:(S\times S)\to(S\times X). This in turn can be split into f_4:(S\times S)\to S and f_5:(S\times S)\to X) so that :f_2(s_1)(s_2) = f_3(s_1,s_2) = \Big(f_4(s_1,s_2),f_5(s_1,s_2)\Big) Then we can re-express f\in S(S(X)) as :f:S\times S\to S\times S\times X, \qquad f(s_1,s_2) = \Big(f_1(s_1),f_4(s_1,s_2),f_5(s_1,s_2)\Big) We can now give the join as \mu_X(f): S\to S\times X : \big(\mu_X(f)\big)(s)=\Big(f_4(s,f_1(s)),f_5(s,f_1(s))\Big) In functional programming and denotational semantics, the state monad models
stateful computations.
The environment monad Given a set E, the endofunctor of the
reader or
environment monad maps each set X to the set of functions E\to X. Thus, the endofunctor of this monad is exactly the
hom functor \mathrm{Hom}(E, -). The component of the unit at X maps each element x\in X to the
constant function e\mapsto x. The multiplication maps a
two-variable function f: E \to (E \to X) to its "diagonal component" (e \mapsto f(e, e)) : E \to X . In other words, multiplication is precomposition with : \Delta : E \to E \times E : e \mapsto (e, e). In functional programming and denotational semantics, the environment monad models computations with access to some read-only data.
The list and set monads The
list or
nondeterminism monad maps a set
X to the set of finite
sequences (i.e.,
lists) with elements from
X. The unit maps an element
x in
X to the singleton list [x]. The multiplication concatenates a list of lists into a single list. In functional programming, the list monad is used to model
nondeterministic computations. The covariant powerset monad is also known as the
set monad, and is also used to model nondeterministic computation. == Algebras for a monad ==