In category theory, a branch of mathematics, a monad (also triple, triad, standard construction and fundamental construction)[1] is an endofunctor (a functor mapping a category to itself), together with two natural transformations required to fulfill certain coherence conditions. Monads are used in the theory of pairs of adjoint functors, and they generalize closure operators on partially ordered sets to arbitrary categories.

Introduction and definition

A monad is a certain type of endofunctor. For example, if ${\displaystyle F}$ and ${\displaystyle G}$ are a pair of adjoint functors, with ${\displaystyle F}$ left adjoint to ${\displaystyle G}$, then the composition ${\displaystyle G\circ F}$ is a monad. If ${\displaystyle F}$ and ${\displaystyle G}$ are inverse functors, the corresponding monad is the identity functor. In general, adjunctions are not equivalencesthey relate categories of different natures. The monad theory matters as part of the effort to capture what it is that adjunctions 'preserve'. The other half of the theory, of what can be learned likewise from consideration of ${\displaystyle F\circ G}$, is discussed under the dual theory of comonads.

Formal definition

Throughout this article ${\displaystyle C}$ denotes a category. A monad on ${\displaystyle C}$ consists of an endofunctor ${\displaystyle T\colon C\to C}$ together with two natural transformations: ${\displaystyle \eta \colon 1_{C}\to T}$ (where ${\displaystyle 1_{C}}$ denotes the identity functor on ${\displaystyle C}$) and ${\displaystyle \mu \colon T^{2}\to T}$ (where ${\displaystyle T^{2}}$ is the functor ${\displaystyle T\circ T}$ from ${\displaystyle C}$ to ${\displaystyle C}$). These are required to fulfill the following conditions (sometimes called coherence conditions):

• ${\displaystyle \mu \circ T\mu =\mu \circ \mu T}$ (as natural transformations ${\displaystyle T^{3}\to T}$);
• ${\displaystyle \mu \circ T\eta =\mu \circ \eta T=1_{T}}$ (as natural transformations ${\displaystyle T\to T}$; here ${\displaystyle 1_{T}}$ denotes the identity transformation from ${\displaystyle T}$ to ${\displaystyle T}$).

We can rewrite these conditions using the following commutative diagrams:

See the article on natural transformations for the explanation of the notations ${\displaystyle T\mu }$ and ${\displaystyle \mu T}$, or see below the commutative diagrams not using these notions:

The first axiom is akin to the associativity in monoids if we think of ${\displaystyle \mu }$ as the monoid's binary operation, and the second axiom is akin to the existence of an identity element (which we think of as given by ${\displaystyle \eta }$). Indeed, a monad on ${\displaystyle C}$ can alternatively be defined as a monoid in the category ${\displaystyle \mathbf {End} _{C}}$ whose objects are the endofunctors of ${\displaystyle C}$ and whose morphisms are the natural transformations between them, with the monoidal structure induced by the composition of endofunctors.

The power set monad is a monad on the category ${\displaystyle \mathbf {Set} }$: For a set ${\displaystyle A}$ let ${\displaystyle T(A)}$ be the power set of ${\displaystyle A}$ and for a function ${\displaystyle f\colon A\to B}$ let ${\displaystyle T(f)}$ be the function between the power sets induced by taking direct images under ${\displaystyle f}$. For every set ${\displaystyle A}$, we have a map ${\displaystyle \eta _{A}\colon A\to T(A)}$, which assigns to every ${\displaystyle a\in A}$ the singleton ${\displaystyle \{a\}}$. The function

${\displaystyle \mu _{A}\colon T(T(A))\to T(A)}$

takes a set of sets to its union. These data describe a monad.

Remarks

The axioms of a monad are formally similar to the monoid axioms. In fact, monads are special cases of monoids, namely they are precisely the monoids among endofunctors ${\displaystyle \operatorname {End} (C)}$, which is equipped with the multiplication given by composition of endofunctors.

The categorical dual definition is a formal definition of a comonad (or cotriple); this can be said quickly in the terms that a comonad for a category ${\displaystyle C}$ is a monad for the opposite category ${\displaystyle C^{\mathrm {op} }}$. It is therefore a functor ${\displaystyle U}$ from ${\displaystyle C}$ to itself, with a set of axioms for counit and comultiplication that come from reversing the arrows everywhere in the definition just given.

Monads are to monoids as comonads are to comonoids. Every set is a comonoid in a unique way, so comonoids are less familiar in abstract algebra than monoids; however, comonoids in the category of vector spaces with its usual tensor product are important and widely studied under the name of coalgebras.

Terminological history

The notion of monad was invented by Roger Godement in 1958 under the name "standard construction." In the 1960s and 1970s, many people used the name "triple." The now standard term "monad" is due to Saunders Mac Lane.

Examples

${\displaystyle F:C\rightleftarrows D:G}$

gives rise to a monad on C. This very widespread construction works as follows: the endofunctor is the composite

${\displaystyle T=G\circ F.}$

This endofunctor is quickly seen to be a monad, where the unit map stems from the unit map ${\displaystyle \operatorname {id} _{C}\to G\circ F}$ of the adjunction, and the multiplication map is constructed using the counit map of the adjunction:

${\displaystyle T^{2}=G\circ F\circ G\circ F{\stackrel {G\circ {\text{counit}}\circ F}{\to }}G\circ F=T.}$

Double dualization

The double dualization monad, for a fixed field k arises from the adjunction

${\displaystyle (-)^{*}:\mathbf {Vect} _{k}\rightleftarrows \mathbf {Vect} _{k}^{op}:(-)^{*}}$

where both functors are given by sending a vector space V to its dual vector space ${\displaystyle V^{*}:=\operatorname {Hom} (V,k)}$. The associated monad sends a vector space V to its double dual ${\displaystyle V^{**}}$. This monad is discussed, in much greater generality, by Kock (1970). Another instance of the same paradigm, discussed by Riehl (2017, Ex. 5.1.4), is the double power set monad, which is the monad on the category of sets, sending a set X to

${\displaystyle T(X)=\operatorname {Hom} (\operatorname {Hom} (X,2),2)}$

where 2 denotes a 2-element set, and ${\displaystyle \operatorname {Hom} (X,2)}$ is the power set of a set X.

Closure operators on partially ordered sets

For categories arising from partially ordered sets ${\displaystyle (P,\leq )}$ (with a single morphism from ${\displaystyle x}$ to ${\displaystyle y}$ iff ${\displaystyle x\leq y}$), then the formalism becomes much simpler: adjoint pairs are Galois connections and monads are closure operators.

For example, let ${\displaystyle G}$ be the forgetful functor from the category Grp of groups to the category Set of sets, and let ${\displaystyle F}$ be the free group functor from the category of sets to the category of groups. Then ${\displaystyle F}$ is left adjoint of ${\displaystyle G}$. In this case, the associated monad ${\displaystyle T=G\circ F}$ takes a set ${\displaystyle X}$ and returns the underlying set of the free group

${\displaystyle \mathrm {Free} (X)}$. The unit map of this monad is given by the maps

${\displaystyle X\rightarrow T(X)}$

including any set ${\displaystyle X}$ into the set ${\displaystyle \mathrm {Free} (X)}$ in the natural way, as strings of length 1. Further, the multiplication of this monad is the map

${\displaystyle T(T(X))\rightarrow 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 ${\displaystyle T}$ is the endofunctor on the category of vector spaces which maps a vector space ${\displaystyle V}$ to its tensor algebra ${\displaystyle T(V)}$, and which maps linear maps to their tensor product. We then have a natural transformation corresponding to the embedding of ${\displaystyle V}$ into its tensor algebra, and a natural transformation corresponding to the map from ${\displaystyle T(T(V))}$ to ${\displaystyle T(V)}$ obtained by simply expanding all tensor products.

Under mild conditions, functors not admitting a left adjoint also give rise to a monad, the so-called codensity monad. For example, the inclusion

${\displaystyle \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 monad is a submonad of the above-mentioned double power set monad. This and similar examples are discussed in Leinster (2013).

Given a monad ${\displaystyle (T,\eta ,\mu )}$ on a category ${\displaystyle C}$, it is natural to consider ${\displaystyle T}$-algebras, i.e., objects of C acted upon by T in a way which is compatible with the unit and multiplication of the monad. More formally, a T-algebra ${\displaystyle (x,h)}$ is an object ${\displaystyle x}$ of ${\displaystyle C}$ together with an arrow ${\displaystyle h\colon Tx\to x}$ of ${\displaystyle C}$ called the structure map of the algebra such that the diagrams

 and

commute.

A morphism ${\displaystyle f\colon (x,h)\to (x',h')}$ of ${\displaystyle T}$-algebras is an arrow ${\displaystyle f\colon x\to x'}$ of ${\displaystyle C}$ such that the diagram

commutes. T-algebras form a category called the Eilenberg–Moore category and denoted by ${\displaystyle C^{T}}$. For example, for the free group monad discussed above, a T-algebra is a set X together with a map from the free group generated by X towards X subject to associativity and unitality conditions. Such a structure is equivalent to saying that X is a group itself.

Another example is the distribution monad on the category of sets. It is defined by sending a set X to the set of functions ${\displaystyle f:X\to [0,1]}$ with finite support and so that ${\displaystyle \sum _{x\in X}f(x)=1}$. By inspection of the definitions, it can be shown that algebras over the distribution monad are equivalent to convex sets, i.e., sets equipped with operations ${\displaystyle x+_{r}y}$ for ${\displaystyle r\in [0,1]}$ subject to axioms resembling the behavior of convex linear combinations ${\displaystyle rx+(1-r)y}$ in Euclidean space.[2]

${\displaystyle T(-):C\rightleftarrows C^{T}:{\text{forget}}}$

whose left adjoint sends an object X to the free T-algebra T(X). However, there are usually several distinct adjunctions giving rise to a monad: let ${\displaystyle \mathbf {Adj} (C,T)}$ be the category whose objects are the adjunctions ${\displaystyle (F,G,e,\varepsilon )}$ such that ${\displaystyle (GF,e,G\varepsilon F)=(T,\eta ,\mu )}$ and whose arrows are the morphisms of adjunctions that are the identity on ${\displaystyle C}$. Then the above free-forgetful adjunction involving the Eilenberg–Moore category ${\displaystyle C^{T}}$ is a terminal object in ${\displaystyle \mathbf {Adj} (C,T)}$. An initial object is the Kleisli category, which is by definition the full subcategory of ${\displaystyle C^{T}}$ consisting only of free T-algebras, i.e., T-algebras of the form ${\displaystyle T(x)}$ for some object x of C.

Given any adjunction ${\displaystyle (F:C\to D,G:D\to C,\eta ,\varepsilon )}$ with associated monad T, the functor G can be factored as

${\displaystyle D{\stackrel {\tilde {G}}{\to }}C^{T}{\stackrel {\text{forget}}{\to }}C,}$

i.e., G(Y) can be naturally endowed with a T-algebra structure for any Y in D. The adjunction is called a monadic adjunction if the first functor ${\displaystyle {\tilde {G}}}$ yields an equivalence of categories between D and the Eilenberg–Moore category ${\displaystyle C^{T}}$.[3] By extension, a functor ${\displaystyle G\colon D\to C}$ is said to be monadic if it has a left adjoint ${\displaystyle F}$ forming a monadic adjunction. For example, the free-forgetful adjunction between groups and sets is monadic, since algebras over the associated monad are groups, as was mentioned above. In general, knowing that an adjunction is monadic allows to reconstruct objects in D out of objects in C and the T-action.

Beck's monadicity theorem gives a necessary and sufficient condition for an adjunction to be monadic. A simplified version of this theorem states that G is monadic if it is conservative (or G reflects isomorphisms, i.e., a morphism in D is an isomorphism if and only if its image under G is an isomorphism in C) and C has and G preserves coequalizers.

For example, the forgetful functor from the category of compact Hausdorff spaces to sets is monadic. However the forgetful functor from all topological spaces to sets is not conservative since there are continuous bijective maps (between non-compact or non-Hausdorff spaces) that fail to be homeomorphisms. Thus, this forgetful functor is not monadic.[4] The dual version of Beck's theorem, characterizing comonadic adjunctions, is relevant in different fields such as topos theory and topics in algebraic geometry related to descent. A first example of a comonadic adjunction is the adjunction

${\displaystyle -\otimes _{A}B:\mathbf {Mod} _{A}\rightleftarrows \mathbf {Mod} _{B}:\operatorname {forget} }$

for a ring homomorphism ${\displaystyle A\to B}$ between commutative rings. This adjunction is comonadic, by Beck's theorem, if and only if B is faithfully flat as an A-module. It thus allows to descend B-modules, equipped with a descent datum (i.e., an action of the comonad given by the adjunction) to A-modules. The resulting theory of faithfully flat descent is widely applied in algebraic geometry.

Uses

Monads are used in functional programming to express types of sequential computation (sometimes with side-effects). See monads in functional programming, and the more mathematically oriented Wikibook module b:Haskell/Category theory.

In categorical logic, an analogy has been drawn between the monad-comonad theory, and modal logic via closure operators, interior algebras, and their relation to models of S4 and intuitionistic logics.

Generalization

It is possible to define monads in a 2-category ${\displaystyle C}$. Monads described above are monads for ${\displaystyle C=\mathbf {Cat} }$.

2. Świrszcz, T., (1974), "Monadic functors and convexity", Bull. Acad. Polon. Sci. Sér. Sci. Math. Astronom. Phys., 22: 39–42, MR 0390019CS1 maint: extra punctuation (link), , doi:10.1007/978-3-642-15240-5_1 Missing or empty |title= (help)