41.05.01 · category-theory / monads-algebras

Monads, Eilenberg-Moore Algebras, and the Kleisli Category

shipped3 tiersLean: none

Anchor (Master): Mac Lane 1998 *Categories for the Working Mathematician* 2e (Springer GTM 5) Ch. VI in full (the Eilenberg-Moore and Kleisli resolutions, the two adjunctions resolving a monad, the comparison functors, comonads); Borceux 1994 *Handbook of Categorical Algebra 2* (Cambridge) Ch. 4; Eilenberg-Moore 1965 *Adjoint functors and triples*; Kleisli 1965 *Every standard construction is induced by a pair of adjoint functors*

Intuition Beginner

A great many constructions take a thing and wrap it in extra structure of a fixed kind. Take a set and form all finite lists you can build from its elements. Take a set and form all the formal weighted blends of its elements. Take a set and form all its subsets. Each of these is a way of packaging the original thing inside a roomier container, always the same kind of container. A monad is the bookkeeping that says how such a packaging behaves: how a bare element slips into the container as the simplest possible package, and how a container full of containers collapses back down into one.

Two small habits make a packaging a monad. First, any plain element can be put into the container in the most economical way, as a one-item package with nothing extra added. Second, whenever you end up with a package of packages, there is one honest way to flatten it into a single package. A list of lists flattens by concatenation. A blend of blends flattens by multiplying the weights through. Once these two habits agree with each other in the obvious bookkeeping, you have a monad.

Why bother naming this? Because the same two habits show up everywhere, and pinning them down lets you reason about lists, probabilities, subsets, and computations that might fail, all with one vocabulary instead of a separate story each time.

Visual Beginner

Picture a machine that wraps things. Feed it a set of plain items on the left and it returns the set of all packages built from those items on the right. The list machine returns all finite lists; the subset machine returns all subsets; the blend machine returns all weighted blends.

Two arrows control the machine. The "wrap" arrow takes a bare item and returns its simplest package: the one-item list, the singleton subset, the blend that puts all its weight on that single item. The "flatten" arrow takes a package whose contents are themselves packages and merges them into one package at a single level.

feature the wrap arrow (unit) the flatten arrow (multiplication)
takes in a bare item a package of packages
returns the simplest one-item package one merged package
list machine the one-element list concatenate all the inner lists
subset machine the singleton take the union of all inner subsets
blend machine all weight on multiply outer and inner weights

The picture's point is that wrap and flatten are not arbitrary. Flattening twice from the outside must agree with flattening twice from the inside, and wrapping then flattening must give back what you started with. Those agreements are the laws of a monad.

Worked example Beginner

Work with the list machine on a small set, . A package here is a finite list, such as , , or the empty list .

Step 1. Wrap. The wrap arrow sends the bare item to the one-item list , and sends to . Nothing extra is added; the package holds exactly one item.

Step 2. Build a package of packages. Consider the list of lists . Its two entries are themselves lists. This is what the flatten arrow is built to handle.

Step 3. Flatten. Concatenating the inner lists in order glues to , giving the single list . The two-level package has become one level.

Step 4. Check the wrap-then-flatten habit. Start from the plain list . Wrap each entry to get the list of one-item lists , then flatten by concatenation: glued to is . You are back where you began.

What this tells us: wrapping puts an item in as a length-one package, flattening glues nested packages into one, and the two are tuned so that introducing a layer and then removing it changes nothing. Those exact habits, holding for every list, are what make the list machine a monad.

Check your understanding Beginner

Formal definition Intermediate+

Let be a category. A monad on is a triple where is an endofunctor and (the unit) and (the multiplication) are natural transformations making the associativity and unit squares commute [Mac Lane 1998]:

Here and are the whiskered composites of 41.01.02. A monad is exactly a monoid in the endofunctor category : the monoidal product is functor composition, the multiplication is , and the unit is , with the two diagrams the monoid associativity and unit laws transcribed. Notation introduced here ( for the monad endofunctor, for the unit, for the multiplication, and below) is recorded in _meta/NOTATION.md.

Definition (the monad of an adjunction). Let with , , unit and counit from 41.03.01. Then carries a monad structure with this same as unit and as multiplication. Dually carries a comonad structure on .

Definition (Eilenberg-Moore algebra). A -algebra (or Eilenberg-Moore algebra) for a monad is a pair with an object of and a structure map satisfying the unit law and the associativity law . A morphism of -algebras is a map with . These form the Eilenberg-Moore category . There is a forgetful functor , , and a free functor sending to the free algebra .

Definition (Kleisli category). The Kleisli category has the same objects as ; a morphism in is a -morphism . The identity on is , and the Kleisli composite of and is . There is a free functor (identity on objects, ) left adjoint to , .

The corpus of monads mirrors the free-forgetful gallery of 41.03.01. The free-monoid monad on has algebras the monoids; the free-group monad has algebras the groups; the free -module monad has algebras the -modules; the powerset monad (with the singleton and the union) has algebras the complete sup-semilattices (equivalently complete lattices); the distribution monad of finitely-supported probability measures has algebras the convex sets. In functional programming the list, Maybe, and state monads package nondeterminism, partiality, and mutable state, and a program with effects is a Kleisli arrow.

Counterexamples to common slips Intermediate+

  • A structure map is more than a left inverse to the unit. The unit law alone does not make an algebra; the associativity law is an independent constraint and is what forces to respect nesting. For the list monad it is exactly the law that a monoid multiplication is associative.

  • Not every underlies an algebra. For the powerset monad an algebra structure on is a join operation that is associative and unital in the monad sense, which forces to be a complete sup-semilattice; an arbitrary set map choosing one element of each subset is not an algebra unless it is a genuine supremum.

  • The Kleisli and Eilenberg-Moore categories are different in general. is equivalent to the full subcategory of free algebras inside ; the inclusion is an equivalence onto all of only when every algebra is free, which fails already for the list monad, where most monoids are not free.

Key theorem with proof Intermediate+

The signature result is that monads and adjunctions are tied at the source: every adjunction produces a monad, and the construction is the engine behind every later resolution.

Theorem (the monad of an adjunction). Let with unit and counit . Then with and is a monad on [Mac Lane 1998].

Proof. The unit and the natural transformation are natural as composites and whiskerings of natural transformations. For the right unit law, . Evaluating the second triangle identity of 41.03.01 and whiskering on the right by gives , so . For the left unit law, ; the first triangle identity gives , so applying yields . For associativity, both and unfold to versus . Naturality of at the morphism reads (both equal as maps after applying ); applying and whiskering supplies , which is . Hence satisfies the monad laws.

Bridge. This theorem builds toward the converse — that every monad arises from an adjunction — and appears again in the Master tier, where the Eilenberg-Moore and Kleisli categories furnish two canonical such adjunctions. The foundational reason the monad laws fall out of the triangle identities is that inherits associativity from the single naturality square of the counit at , and the unit laws are the two triangle identities of 41.03.01 read through and ; this is exactly the calculation that turns the data of an adjunction into a monoid in . The construction generalises the free-monoid example of the Beginner tier, where is the list endofunctor and is concatenation, and it is dual to the comonad on built from the same data with and trading roles. Putting these together, the central insight is that an adjunction carries strictly more information than its monad — many adjunctions can induce the same — and the bridge is that the surplus is organised by a category of resolutions whose initial and terminal objects are the Kleisli and Eilenberg-Moore constructions, the comparison theorem cross-referenced to the monadicity unit 41.05.02.

Exercises Intermediate+

Advanced results Master

Theorem (Eilenberg-Moore and Kleisli resolve every monad). Let be a monad on . The free-forgetful adjunction on and the Kleisli adjunction on each induce exactly [Eilenberg-Moore 1965]. Thus a monad that looks like the shadow of an adjunction is one: every monad is for at least these two adjoint pairs.

Theorem (the category of resolutions; Kleisli initial, Eilenberg-Moore terminal). Fix a monad on and let be the category whose objects are adjunctions , , inducing , and whose morphisms are functors with and . Then the Kleisli resolution is initial and the Eilenberg-Moore resolution is terminal in [Mac Lane 1998]. The terminal mediating functor is the comparison functor , , the unique functor over with ; the initial mediating functor is the comparison out of the Kleisli category.

Theorem (monadicity; statement). An adjunction is monadic when its comparison functor is an equivalence; Beck's theorem characterises monadicity by creating coequalisers of -split pairs. The free-monoid, free-group, free-module, powerset, and compact-Hausdorff adjunctions are all monadic, so , , , complete sup-semilattices, and are recovered as Eilenberg-Moore categories. The full statement and proof, together with the Lawvere-theory presentation of finitary monads, are developed in 41.05.02.

Theorem (comonads, dually). A comonad on is an endofunctor with (counit) and (comultiplication) satisfying the dual laws; it is a comonoid in . Every adjunction gives the comonad on , with coalgebras dual to algebras. The store (costate) comonad and the stream comonad model context-dependent computation as the dual of effectful computation, and the coalgebras of a comonad on a presheaf topos model state machines and transition systems.

Synthesis. Putting these together, a monad is the algebraic residue of an adjunction, and the two canonical adjunctions that resolve it sit at the extreme ends of the category of all resolutions: the Kleisli category is the initial resolution, built from the free algebras alone, and the Eilenberg-Moore category is the terminal resolution, built from all algebras. The foundational reason both exist for every monad is that the monad axioms are exactly the structure needed to define algebra morphisms and Kleisli composition, so the data of already carries its own free-forgetful adjunction. This generalises the free-forgetful gallery of 41.03.01: monoids, groups, modules, complete lattices, and convex sets are the Eilenberg-Moore categories of the free-monoid, free-group, free-module, powerset, and distribution monads, and monadicity 41.05.02 is the statement that an algebraic category is its own category of algebras. This is exactly the perspective that makes the codensity monad — the right Kan extension formed when has no left adjoint — the correct repair of a missing left adjoint, the bridge to the Kan theory of 41.06.02, where the comparison functors of this unit become the universal arrows into a Kan extension. The central insight is that "monad", "monoid in ", "algebraic theory presented by operations and equations", and "shadow of an adjunction" name one structure from four directions.

Full proof set Master

Proposition 1 (the Eilenberg-Moore adjunction induces ). For a monad , the free functor is left adjoint to the forgetful , with unit and counit , and the induced monad is .

Proof. That is an algebra is the associativity and left-unit laws of . For and define by and by . The map is an algebra morphism: , using naturality of and the algebra associativity law. Then by naturality of and the algebra unit law; and , using that is an algebra morphism, rearranged, together with the monad left-unit law . The bijection is natural, so . The counit at is , and the induced multiplication is with component at equal to , while the unit is . Hence the induced monad is .

Proposition 2 (the comparison functor is the unique mediating functor; Eilenberg-Moore is terminal). Let with counit induce . The assignment , , is a functor with and , and it is the unique such functor over .

Proof. That is an algebra: the unit law is , the second triangle identity of 41.03.01; the associativity law reduces, with , to naturality of at after applying . For , is an algebra morphism by naturality of . Then on the nose, and , so . For uniqueness, any functor with has for some structure map ; the requirement that send the counit component to the algebra structure (forced by together with the adjunction triangle for ) pins . So . This exhibits as terminal in .

Proposition 3 (the Kleisli category is the free algebras; Kleisli is initial). The functor , , for , is full, faithful, identity-on-the-free-algebras, and exhibits as initial in .

Proof. Functoriality: by the right-unit law, and for , the Kleisli composite maps under to , which equals by the associativity law and naturality of — the composite of the images. Fullness and faithfulness: algebra morphisms are in bijection with maps by restriction along and extension by as in Proposition 1, and this bijection is exactly on hom-sets. For initiality, given any resolution inducing , the unique functor with and is forced on objects by and on a Kleisli arrow by , the transpose of ; functoriality and the two equations follow from the triangle identities. Uniqueness is forced because every object of is in the image of and every arrow factors through units.

Proposition 4 (the two comparisons compose to the inclusion of free algebras). The composite of the Eilenberg-Moore comparison of the Kleisli adjunction with the Kleisli initial map equals the canonical full embedding onto the free algebras.

Proof. The Kleisli adjunction has counit whose component at (an object of ) is the Kleisli arrow viewed as . Its Eilenberg-Moore comparison sends the object to , the free algebra, and sends a Kleisli arrow to the -image of its transpose, which is . This is exactly as defined in Proposition 3. Both routes therefore land on the free algebra and agree on morphisms, so the composite is the full embedding onto the free algebras, recovering the isomorphism of the Intermediate Exercise 7.

Connections Master

  • Adjunctions 41.03.01. A monad is by construction the data , , extracted from an adjunction , and the monad axioms are the triangle identities and the counit naturality square read through and . Conversely the free-forgetful adjunctions of 41.03.01 — free monoid, free group, free module, free vector space — are precisely the adjunctions whose Eilenberg-Moore categories are , , , and , so this unit explains why the entire free-forgetful gallery is a single phenomenon.

  • Natural transformations and the endofunctor category 41.01.02. A monad is a monoid in the strict monoidal category of 41.01.02, and the whiskered composites , , , appearing in the monad laws are the horizontal composites defined there. The associativity and unit squares are the monoid axioms transcribed into the -categorical language of .

  • Monadicity and Lawvere theories 41.05.02. The comparison functor introduced here is an equivalence exactly when the adjunction is monadic, and Beck's monadicity theorem — characterising this by the creation of -split coequalisers — is proved in 41.05.02, where finitary monads on are identified with Lawvere algebraic theories, making "algebras for a monad" and "models of an equational theory" the same notion.

  • Kan extensions and the codensity monad 41.06.02. When a functor has no left adjoint, the right Kan extension still carries a monad structure, the codensity monad, which is the universal monad through which factors; this is the Kan-theoretic generalisation of the monad of an adjunction developed in 41.06.02, where the comparison functors of this unit reappear as universal arrows into a Kan extension.

  • Limits and colimits 41.02.01. The forgetful functor creates all limits and those colimits preserved by and , so the limit theory of 41.02.01 computes limits of algebras objectwise in ; Beck's monadicity criterion is itself a statement about the creation of a specific class of coequalisers, tying the algebra category's structure to the colimit theory of 41.02.01.

Historical & philosophical context Master

The monad concept emerged in the early 1960s under several names. Roger Godement had used the iterated comonad of a sheaf-cohomology resolution — the "standard construction" — and the abstract pattern was isolated as a triple (the term long preferred by the Eilenberg school) and as a monad (Mac Lane's later coinage, by analogy with the monoid it generalises). The decisive papers appeared together: Samuel Eilenberg and John Moore's Adjoint functors and triples (1965) [Eilenberg-Moore 1965] constructed the category of algebras now bearing their names and proved that it resolves the monad, while Heinrich Kleisli's Every standard construction is induced by a pair of adjoint functors (1965) [Kleisli 1965] constructed the other canonical resolution from the free algebras alone. Peter Huber had observed shortly before that every adjunction yields a monad, posing the converse that these two papers answered.

The systematisation into the two-sided universal property — Kleisli initial, Eilenberg-Moore terminal among resolutions — and the comparison functors belongs to Mac Lane's Categories for the Working Mathematician (1971; 2nd ed. 1998) [Mac Lane 1998], Chapter VI, alongside Jonathan Beck's monadicity theorem from his 1967 Columbia thesis. The recognition that the algebras of the free-monoid, free-group, and powerset monads are monoids, groups, and complete lattices connected monad theory to William Lawvere's 1963 functorial semantics of algebraic theories, and Eugenio Moggi's 1989 Notions of computation and monads transplanted the Kleisli category into programming-language semantics, where a monad models a class of computational effects and a Kleisli arrow is an effectful program.

Bibliography Master

@article{EilenbergMoore1965,
  author  = {Eilenberg, Samuel and Moore, John C.},
  title   = {Adjoint functors and triples},
  journal = {Illinois Journal of Mathematics},
  volume  = {9},
  year    = {1965},
  pages   = {381--398}
}

@article{Kleisli1965,
  author  = {Kleisli, Heinrich},
  title   = {Every standard construction is induced by a pair of adjoint functors},
  journal = {Proceedings of the American Mathematical Society},
  volume  = {16},
  year    = {1965},
  pages   = {544--546}
}

@book{MacLane1998,
  author    = {Mac Lane, Saunders},
  title     = {Categories for the Working Mathematician},
  edition   = {2},
  publisher = {Springer},
  series    = {Graduate Texts in Mathematics 5},
  year      = {1998}
}

@phdthesis{Beck1967,
  author = {Beck, Jonathan M.},
  title  = {Triples, Algebras and Cohomology},
  school = {Columbia University},
  year   = {1967}
}

@article{Moggi1991,
  author  = {Moggi, Eugenio},
  title   = {Notions of computation and monads},
  journal = {Information and Computation},
  volume  = {93},
  number  = {1},
  year    = {1991},
  pages   = {55--92}
}

@book{Borceux1994,
  author    = {Borceux, Francis},
  title     = {Handbook of Categorical Algebra 2: Categories and Structures},
  publisher = {Cambridge University Press},
  series    = {Encyclopedia of Mathematics and its Applications 51},
  year      = {1994}
}