Mathematics.

monads and adjunctions

Monads

Category Theory90 minDifficulty9 out of 10

You should know: functors, natural transformations, adjoint functors

Overview

A monad is a triple (T, η, μ) consisting of an endofunctor T : C → C and two natural transformations — the unit η : Id ⇒ T and the multiplication μ : T² ⇒ T — satisfying associativity and unit laws. Monads unify constructions as diverse as free algebras, powerset, probability distributions, and computational effects (in Haskell). Every adjunction gives rise to a monad, and conversely every monad arises from an adjunction (via the Kleisli or Eilenberg–Moore construction).

Intuition

Think of a monad as a 'box' with two operations: one to put a value in the box (unit η), and one to flatten a nested box into a single box (multiplication μ). The Maybe monad boxes a value that might not exist; the List monad boxes multiple possible values. The monad laws ensure that boxing and flattening behave consistently — nesting doesn't matter and the unit is a neutral element for flattening.

Formal Definition

Definition

A monad on a category C is a triple (T, η, μ) where T : C → C is a functor, η : Id_C ⇒ T is the unit, and μ : T ∘ T ⇒ T is the multiplication, satisfying the following commutative diagrams (monad laws).

μTμ=μμT(associativity)\mu \circ T\mu = \mu \circ \mu T \quad (\text{associativity})

Flattening from the left or right gives the same result

Associativity
μTη=μηT=idT(unit laws)\mu \circ T\eta = \mu \circ \eta T = \text{id}_T \quad (\text{unit laws})

The unit is a two-sided identity for multiplication

Unit laws
Kleisli composition: fg=μCTfg,g:ATB,  f:BTC\text{Kleisli composition: } f \star g = \mu_C \circ Tf \circ g, \quad g : A \to TB,\; f : B \to TC
Kleisli composition

Notation

NotationMeaning
TTThe endofunctor of the monad
η\etaUnit natural transformation Id ⇒ T
μ\muMultiplication natural transformation T² ⇒ T
fgf \star gKleisli composition of two Kleisli morphisms

Properties

Every adjunction yields a monad

IfFGwithF:CD,  G:DC,thenT=GFisamonadwithη=ηadjandμ=GεF.If F \dashv G with F : C \to D,\; G : D \to C, then T = GF is a monad with \eta = \eta^{\text{adj}} and \mu = G\varepsilon F.

Condition: F ⊣ G an adjunction

Eilenberg–Moore algebras

Foramonad(T,η,μ)onC,aTalgebraisapair(A,h:TAA)satisfyinghηA=idAandhμA=hTh.For a monad (T,\eta,\mu) on C, a T-algebra is a pair (A, h : TA \to A) satisfying h \circ \eta_A = \text{id}_A and h \circ \mu_A = h \circ Th.

Beck's monadicity theorem

AfunctorG:DCismonadiciffithasaleftadjoint,reflectsisomorphisms,andDhascoequalizersofGsplitpairs.A functor G : D \to C is monadic iff it has a left adjoint, reflects isomorphisms, and D has coequalizers of G-split pairs.

Worked Examples

  1. Define the powerset functor: for f : A → B, Pf(S) = {f(a) | a ∈ S}.

    P(A)={SSA}P(A) = \{S \mid S \subseteq A\}
  2. The unit η_A : A → PA sends each element to its singleton.

    ηA(a)={a}\eta_A(a) = \{a\}
  3. The multiplication μ_A : PPA → PA takes a set of subsets and unions them.

    μA(S)=SSS\mu_A(\mathcal{S}) = \bigcup_{S \in \mathcal{S}} S
  4. Verify associativity: μ ∘ Pμ = μ ∘ μP. Both sides take a set of sets of sets and flatten it to a set — order doesn't matter since union is associative.

  5. A Kleisli morphism A → PB is a relation (multi-valued function). The Kleisli category of P is the category Rel of sets and relations.

    Kl(P)Rel\text{Kl}(P) \cong \text{Rel}

Answer: The powerset monad has unit η_A(a) = {a} and multiplication μ_A = ∪. Its Kleisli category is the category of sets and relations.

Practice Problems

Difficulty 7/10

Let T = (−) × M for a monoid (M, e, ·) in Set. Define natural transformations η and μ making T a monad, and verify one monad law.

Difficulty 8/10

Describe the Kleisli category of the Maybe monad on Set. What are the objects and morphisms, and what is composition?

Difficulty 9/10

State Beck's monadicity theorem and use it to show that the forgetful functor U : Ab → Set (abelian groups to sets) is monadic.

Common Mistakes

Common Mistake

A monad is just a functor

A monad is a functor equipped with two natural transformations (unit and multiplication) satisfying coherence laws. The extra structure is essential.

Common Mistake

All endofunctors are monads

An endofunctor can fail to admit unit/multiplication natural transformations satisfying the monad laws; additional structure must be specified.

Common Mistake

Kleisli and Eilenberg–Moore categories are the same

Both arise from a monad but are generally different: the Kleisli category is the 'free' construction while Eilenberg–Moore is the 'complete' one; there is a canonical functor Kl(T) → EM(T).

Quiz

Which two natural transformations define a monad?
What is the Kleisli category of the List monad on Set?
Which statement about Eilenberg–Moore algebras is correct?

Historical Background

Monads were introduced by Roger Godement in 1958 under the name 'standard constructions'. Eilenberg and Moore studied the algebras of a monad (now called Eilenberg–Moore algebras) in 1965. Kleisli introduced an alternative category in 1965 as well. The term 'monad' was popularized by Saunders Mac Lane. Eugenio Moggi's 1991 paper showed monads model computational effects, making them fundamental in functional programming.

  1. 1958

    Godement introduces 'standard constructions' (monads)

    Roger Godement

  2. 1965

    Eilenberg–Moore algebras and Kleisli category defined

    Samuel Eilenberg, John Moore, Heinrich Kleisli

  3. 1991

    Moggi uses monads to model computational effects

    Eugenio Moggi

  4. 1992

    Wadler popularises monads in functional programming

    Philip Wadler

Summary

  • A monad (T, η, μ) on C is an endofunctor with a unit η : Id ⇒ T and multiplication μ : T² ⇒ T satisfying associativity and unit laws.
  • Every adjunction F ⊣ G yields a monad T = GF; conversely every monad arises from two adjunctions — Kleisli and Eilenberg–Moore.
  • The Kleisli category Kl(T) has the same objects as C; morphisms A → B are C-morphisms A → TB composed via μ.
  • Eilenberg–Moore T-algebras generalise the notion of 'module over T'; e.g., free-monoid monad gives monoids, free-abelian-group monad gives abelian groups.
  • Monads model computational effects in functional programming: Maybe (partiality), List (non-determinism), State, IO, etc.

References

  1. BookMac Lane, S. — Categories for the Working Mathematician, 2nd ed., Ch. VI
  2. BookRiehl, E. — Category Theory in Context, Ch. 5
  3. PaperMoggi, E. — Notions of Computation and Monads (1991)