Monads and the Monad Laws
Summary
A monad on a category is an endofunctor equipped with two natural transformations — a unit and a multiplication — satisfying an associativity law and a unit law . These are exactly the associativity and unit axioms for a monoid, internalized in the strict monoidal category of endofunctors (composition as the tensor product, as the unit object). The dual notion on is a comonad.
Overview
The abstract definition is simple to state but it is the engine of the whole chapter. The data is “potentially borne by objects” — it is a syntactic description of an algebraic structure, which gets interpreted via algebras. Crucially, the two coherence diagrams are literally the monoid axioms once one views composition of endofunctors as a (strict) monoidal product; see Monads - Overview.
Main Content
Monad (Definition 5.1.1)
A monad on a category consists of
- an endofunctor ,
- a unit natural transformation , and
- a multiplication natural transformation ,
so that the following diagrams commute in the functor category :
Associativity.
i.e.
Unit (left and right). With flanking and identities on the diagonals:
Here etc. are whiskered composites of with .
A monad is a monoid in (Remark 5.1.2)
The diagrams of Definition 5.1.1 are exactly the associativity and unit laws for a monoid. This is no coincidence: a monad on is precisely a monoid in the monoidal category of endofunctors of , where the binary functor is composition and the unit object is the identity endofunctor . (The category of endofunctors is a strict monoidal category, so the coherence isomorphisms are identities.) This is the precise content of Wadler’s quip “a monad is a monoid in the category of endofunctors, what’s the problem?”
Comonad (Definition 5.1.6)
A comonad on is a monad on : explicitly, an endofunctor together with a counit and a comultiplication satisfying the dual coassociativity () and counit () laws. A comonad is a comonoid in ; dually to Lemma 5.1.3, any adjunction induces a comonad on the codomain of its left adjoint.
Monads/comonads on a preorder (Example 5.1.7)
A monad on a preorder is an order-preserving function with and . If is a poset these force , and such a is a closure operator. Dually a comonad on a poset is a kernel (interior) operator: and . Example: on the powerset of subsets of a topological space, (closure) is a closure operator and (interior) is a kernel operator.
Examples
These are the canonical monads on (Examples 5.1.4–5.1.5); each comes from a free forgetful adjunction (see Adjunctions Induce Monads):
The free-monoid / list monad (Example 5.1.4(ii))
Induced by the free forgetful adjunction between monoids and sets. The endofunctor is
the set of finite lists of elements of (hence “list monad” in CS). The unit sends to the singleton list (the evident coproduct inclusion). The multiplication is concatenation: it flattens a list of lists into a single list.
The maybe monad (Example 5.1.4(i))
Induced by the free forgetful adjunction between pointed sets and sets. The endofunctor adjoins a new disjoint basepoint, . The unit is the inclusion; the multiplication sends both new points to the single new point. In CS this models partially-defined (“nullable”) values.
The (covariant) power-set monad (Example 5.1.5(i))
, the covariant power-set functor (acting on maps by direct image ). The unit sends to the singleton ; the multiplication takes the union of a set of subsets. (Naturality of uses that direct image, being a left adjoint, preserves unions.) Related: the double power-set monad (Example 5.1.4(vii)) and, with replaced by an arbitrary set, the continuation monads .
Other notable monads
- Free -module monad (Example 5.1.4(iii)): finite formal -linear combinations; special cases are the free abelian group monad and free vector space monad.
- Free group monad of reduced words in letters (Example 5.1.4(iv)).
- Ultrafilter / Stone–Čech monad , the set of ultrafilters on (Example 5.1.4(v)).
- State monad and the “discrete time” monad (Example 5.1.5(iii)); the Giry monad of probability measures on (Example 5.1.5(iv)).
Connections
- This definition is the abstract counterpart of the construction in Adjunctions Induce Monads: there , is the adjunction unit, and , and the monad laws follow from the triangle identities.
- The laws reappear verbatim as the conditions defining an algebra (unit and associativity of the action).
- Requires Functors (endofunctor) and Natural Transformations (the components ; whiskering , ).
- See Monads - Overview for how these fit into the larger story.