---
title: Algebras for a Monad
module: Monads and Algebras
moduleNumber: 7
lessonNumber: 2
order: 702
summary: >
  An algebra for a monad is an object with a structure map that interacts
  correctly with the unit and multiplication. The algebras form the
  Eilenberg–Moore category, whose free–forgetful adjunction induces the monad
  back; a comparison functor relates any other inducing adjunction to it, and
  for the list monad the algebras are exactly monoids.
topics: [Monads and Algebras]
sources:
  - book: Barr & Wells
    ref: "§14.4 Factorizations of a triple; §14.4.2 Eilenberg–Moore algebras; §14.4.3–14.4.4"
  - book: Leinster
    ref: "Notes and further reading (monads and their algebras)"
draft: false
---

A [monad](/category-theory/monads-algebras/monads) $\mathbb{T} = (T, \eta, \mu)$
on $\mathcal{A}$ was built to be the trace of an adjunction, but the definition
never mentions one. Every monad does arise from an adjunction, and the
construction that proves it also identifies the structure a monad describes: its
**algebras**, objects equipped with a map $TA \to A$ that evaluates $T$-structure.
The category they form, due to Eilenberg and Moore, carries a free–forgetful
adjunction inducing exactly $\mathbb{T}$.[^bw-em]

For the list monad an algebra is a set with a way of multiplying out any finite
list of its elements, subject to consistency laws that make it a monoid. Monads
in this sense present universal algebra through arrows.

## Algebras and their axioms

> **Definition ($\mathbb{T}$-algebra).** Let $\mathbb{T} = (T, \eta, \mu)$ be a
> monad on $\mathcal{A}$. A **$\mathbb{T}$-algebra** is a pair $(A, a)$ with
> $A$ an object of $\mathcal{A}$ and $a : TA \to A$ an arrow (the **structure
> map**), such that the two diagrams commute:
>
> $$
> a \circ Ta = a \circ \mu_A : T^2 A \to A
> \qquad\text{(associativity)},
> $$
>
> $$
> a \circ \eta_A = \mathrm{id}_A : A \to A
> \qquad\text{(unit)}.
> $$

The two axioms mirror the two monad laws, one level down.

- **Unit axiom.** An element inserted into $TA$ as a trivial structure by
  $\eta_A$ must evaluate to itself. For the list monad: evaluating the
  singleton list $[a]$ returns $a$.
- **Associativity axiom.** Given a doubly-nested structure in $T^2 A$, the two
  ways of evaluating it — flatten first with $\mu_A$, or evaluate the inner
  layer first with $Ta$ — must agree.

$$
% caption: The two algebra axioms for a structure map $a : T A \to A$, written
% with $m$ for the multiplication and $u$ for the unit. Left: evaluating inner
% structure first ($T a$) or flattening first ($m_A$) agree. Right: trivial
% structure evaluates to the identity.
\begin{tikzpicture}[>=stealth, font=\small,
  nd/.style={minimum size=8mm, inner sep=2pt}]
  \definecolor{acc}{HTML}{4A6FA5}
  \node[nd] (tta) at (0,2.4)   {$T^2 A$};
  \node[nd] (ta1) at (2.9,2.4) {$T A$};
  \node[nd] (ta2) at (0,0)     {$T A$};
  \node[nd] (a1)  at (2.9,0)   {$A$};
  \draw[->, acc, thick] (tta) -- (ta1) node[midway, above] {$m_A$};
  \draw[->, acc, thick] (tta) -- (ta2) node[midway, left]  {$Ta$};
  \draw[->, acc, thick] (ta1) -- (a1)  node[midway, right] {$a$};
  \draw[->, acc, thick] (ta2) -- (a1)  node[midway, below] {$a$};
  \begin{scope}[xshift=5.8cm]
    \node[nd] (a2)  at (0,2.4)   {$A$};
    \node[nd] (ta3) at (2.9,2.4) {$T A$};
    \node[nd] (a3)  at (2.9,0)   {$A$};
    \draw[->, acc, thick] (a2) -- (ta3) node[midway, above] {$u_A$};
    \draw[->, acc, thick] (ta3) -- (a3) node[midway, right] {$a$};
    \draw[->, black, thick] (a2) -- (a3) node[midway, below left] {id};
  \end{scope}
\end{tikzpicture}
$$

Barr & Wells distinguish an algebra **for the endofunctor** $T$ (any pair
$(A, a)$ with $a : TA \to A$, no axioms) from an algebra **for the monad**
$\mathbb{T}$, which is an endofunctor algebra satisfying the two laws
above.[^bw-def] The unconstrained version has its own theory, taken up in
[algebras for an endofunctor](/category-theory/monads-algebras/algebras-for-endofunctors);
here the laws tie evaluation to the monad's unit and
multiplication.

> **Definition (Morphism of algebras).** A morphism
> $f : (A, a) \to (B, b)$ of $\mathbb{T}$-algebras is an arrow $f : A \to B$ of
> $\mathcal{A}$ such that $f \circ a = b \circ Tf$.

$$
% caption: An algebra morphism commutes with the structure maps: applying $T$
% to $f$ and then evaluating in $B$ equals evaluating in $A$ and then applying
% $f$.
\begin{tikzpicture}[>=stealth, font=\small,
  nd/.style={minimum size=8mm, inner sep=2pt}]
  \definecolor{acc}{HTML}{4A6FA5}
  \node[nd] (ta) at (0,2.2)   {$T A$};
  \node[nd] (tb) at (3.2,2.2) {$T B$};
  \node[nd] (a)  at (0,0)     {$A$};
  \node[nd] (b)  at (3.2,0)   {$B$};
  \draw[->, acc, thick] (ta) -- (tb) node[midway, above] {$Tf$};
  \draw[->, acc, thick] (ta) -- (a)  node[midway, left]  {$a$};
  \draw[->, acc, thick] (tb) -- (b)  node[midway, right] {$b$};
  \draw[->, acc, thick] (a)  -- (b)  node[midway, below] {$f$};
\end{tikzpicture}
$$

Composition and identities are inherited from $\mathcal{A}$, so the
$\mathbb{T}$-algebras and their morphisms form a category.

> **Definition (Eilenberg–Moore category).** The category of
> $\mathbb{T}$-algebras and algebra morphisms is the **Eilenberg–Moore
> category** of $\mathbb{T}$, written $\mathcal{A}^{\mathbb{T}}$.

## Algebras of the list monad are monoids

Let $\mathbb{T}$ be the list monad on $\mathbf{Set}$: $TA = A^\ast$, unit
$a \mapsto [a]$, multiplication = concatenation. An algebra is a set $A$ with a
map $\alpha : A^\ast \to A$ evaluating every finite list to an element.
Define a binary operation and a constant by

$$
x \cdot y = \alpha([x, y]),
\qquad
e = \alpha([\,]).
$$

The algebra axioms force $(A, \cdot, e)$ to be a monoid, and conversely every
monoid gives an algebra by $n$-fold multiplication.[^bw-listalg]

- **Unit axiom** gives $\alpha([x]) = x$: singleton lists evaluate trivially.
- **Associativity axiom** applied to the nested list $[[x,y],[z]]$ gives
  $(x \cdot y)\cdot z = \alpha([x,y,z])$, and applied to $[[x],[y,z]]$ gives
  $x \cdot (y \cdot z) = \alpha([x,y,z])$. Both products equal the flat
  evaluation, hence each other.
- **Unit element.** The same axiom on $[[\,],[x]]$ gives
  $e \cdot x = \alpha([x]) = x$, and symmetrically $x \cdot e = x$.

Algebra morphisms are exactly monoid homomorphisms: commuting with $\alpha$ on
two-element lists is preserving the product, and on the empty list is
preserving the unit. So $\mathbf{Set}^{\mathbb{T}} \simeq \mathbf{Mon}$.

> **Worked example (List algebras are monoids, both directions).** Take the
> monoid $(\mathbb{N}, +, 0)$.
>
> _Monoid to algebra._ Define $\alpha : \mathbb{N}^\ast \to \mathbb{N}$ by summing:
> $\alpha([n_1, \ldots, n_k]) = n_1 + \cdots + n_k$ and $\alpha([\,]) = 0$. The
> unit axiom holds, $\alpha(\eta_{\mathbb{N}}(5)) = \alpha([5]) = 5$. The
> associativity axiom holds on $\Lambda = \big[\,[2, 3],\ [1]\,\big]$: flattening
> first gives $\mu_{\mathbb{N}}(\Lambda) = [2, 3, 1]$ and $\alpha([2, 3, 1]) = 6$,
> while evaluating the inner layer first gives
> $T\alpha(\Lambda) = [\,\alpha([2, 3]),\ \alpha([1])\,] = [5, 1]$ and
> $\alpha([5, 1]) = 6$.
>
> _Algebra to monoid._ From that same $\alpha$, recover a product and unit by
> $x \cdot y = \alpha([x, y])$ and $e = \alpha([\,])$, giving $x \cdot y = x + y$
> and $e = 0$ back. Associativity of $\cdot$ is the algebra associativity axiom:
> $$
> (2 \cdot 3) \cdot 1 = \alpha\big([\,\alpha([2, 3]),\ 1\,]\big) = \alpha([5, 1]) = 6,
> \qquad
> 2 \cdot (3 \cdot 1) = \alpha\big([\,2,\ \alpha([3, 1])\,]\big) = \alpha([2, 4]) = 6,
> $$
> both equal to the flat evaluation $\alpha([2, 3, 1]) = 6$. The two passages are
> mutually inverse, so $\mathbf{Set}^{\mathbb{T}} \simeq \mathbf{Mon}$.

The pattern generalizes far beyond lists. A theorem of Linton states that every
equationally defined category of one-sorted algebraic structures — groups,
rings, modules over a fixed ring, lattices — is equivalent to the
Eilenberg–Moore category of some monad on $\mathbf{Set}$; the converse holds
too if infinitary operations are permitted.[^bw-linton] Monads on $\mathbf{Set}$
and algebraic theories are two presentations of the same subject.

| Monad on $\mathbf{Set}$ | $TA$ | Its algebras |
| --- | --- | --- |
| list | $A^\ast$ | monoids |
| maybe | $A + 1$ | pointed sets |
| writer over a monoid $M$ | $M \times A$ | $M$-sets (sets with an $M$-action) |
| free group | reduced words over $A \cup A^{-1}$ | groups |
| free $R$-module | finite formal $R$-combinations of $A$ | $R$-modules |

The maybe row is worth checking by hand: a structure map $A + 1 \to A$
satisfying the unit law is the identity on $A$ plus a choice of basepoint
(the image of the extra point), and the associativity law is automatic. An
algebra is a set with a distinguished element, and morphisms preserve it.

> **Worked example (Maybe algebras are pointed sets).** For the maybe monad
> $TA = A + 1$, a structure map $\alpha : A + 1 \to A$ is fixed by the unit law
> $\alpha \circ \eta_A = \mathrm{id}_A$, which forces $\alpha(\mathsf{just}(a)) = a$,
> together with its value on the extra point, $\alpha(\mathsf{no}) = p$. Take
> $A = \{0, 1, 2\}$ and $p = 0$. The associativity axiom
> $\alpha \circ T\alpha = \alpha \circ \mu_A$ holds on every point of $(A + 1) + 1$:
> $$
> \mathsf{just}(\mathsf{just}(1)) \longmapsto 1,
> \qquad
> \mathsf{just}(\mathsf{no}) \longmapsto 0,
> \qquad
> \mathsf{no} \longmapsto 0,
> $$
> by either route. A maybe-algebra is therefore a set with a distinguished
> element $p$, and an algebra morphism $f$ satisfies $f(p_A) = p_B$: the category
> of maybe-algebras is the category of pointed sets.

The writer row is the same computation for the representation monad
$TA = M \times A$ of a monoid $M$. A structure map $\alpha : M \times A \to A$
is a binary operation $m \cdot a = \alpha(m, a)$. The unit axiom demands
$1_M \cdot a = a$, since $\eta_A(a) = (1_M, a)$. For the associativity axiom,
chase an element $(m_1, m_2, a) \in M \times M \times A = T^2 A$ around the
square: the route through $T\alpha$ gives $m_1 \cdot (m_2 \cdot a)$, and the
route through $\mu_A$ gives $(m_1 m_2) \cdot a$. The two axioms reproduce the
two laws of a monoid action, so the algebras are $M$-sets and their morphisms
are the equivariant maps — recovering by pure diagram chasing the category that
originally induced the monad.

## The free–forgetful adjunction

The Eilenberg–Moore category resolves the monad into an adjunction.

- **Forgetful functor** $U : \mathcal{A}^{\mathbb{T}} \to \mathcal{A}$ sends
  $(A, a) \mapsto A$ and an algebra morphism to itself as an arrow of
  $\mathcal{A}$.
- **Free functor** $F : \mathcal{A} \to \mathcal{A}^{\mathbb{T}}$ sends
  $A \mapsto (TA, \mu_A)$ and $f \mapsto Tf$.

The pair $(TA, \mu_A)$ is the **free algebra** on $A$: its carrier is $TA$
and its structure map is the monad multiplication. The algebra axioms for it
restate the associativity and unit laws of the monad itself, so no new
verification is needed: the monad laws are the statement that free algebras
are algebras.

> **Proposition (Eilenberg–Moore factorization).** $F$ is left adjoint to $U$,
> and the monad induced on $\mathcal{A}$ by $F \dashv U$ is precisely
> $\mathbb{T}$.[^bw-emprop]

The unit of the adjunction is $\eta$ itself. The counit at an algebra $(A, a)$
is the structure map $a$, viewed as an algebra morphism
$(TA, \mu_A) \to (A, a)$ — the associativity axiom is what makes $a$ such
a morphism. Composing, $UF = T$ and
$U\varepsilon F = \mu$, so the induced monad is the one we started with. Every
monad therefore arises from at least one adjunction.

$$
% caption: The Eilenberg–Moore resolution, with $\mathbf{A}$ standing for the
% base category $\mathcal{A}$: the free functor $F$ sends $A$ to the free
% algebra on $A$, the forgetful functor $U$ returns the carrier, and the round
% trip $U F$ is the monad $T$.
\begin{tikzpicture}[>=stealth, font=\small]
  \definecolor{acc}{HTML}{4A6FA5}
  \node[draw, minimum width=34mm, minimum height=11mm] (em) at (0,2.5) {$\mathbf{A}^{T}$ (algebras)};
  \node[draw, minimum width=34mm, minimum height=11mm] (a)  at (0,0)   {$\mathbf{A}$};
  \draw[->, acc, thick] ([xshift=-6mm]a.north) -- ([xshift=-6mm]em.south) node[midway, left] {$F$ free};
  \draw[->, acc, thick] ([xshift=6mm]em.south) -- ([xshift=6mm]a.north) node[midway, right] {$U$ forgetful};
  \draw[->, black, thick] (a.north west) to[out=155, in=205, looseness=2.2] node[midway, left] {$T = UF$} (a.south west);
  \node[font=\footnotesize] at (3.3,1.25) {adjoint pair};
\end{tikzpicture}
$$

## The comparison functor

The Eilenberg–Moore adjunction is not the only one inducing $\mathbb{T}$; the
[Kleisli construction](/category-theory/monads-algebras/kleisli-and-programming)
gives another, and concrete free–forgetful adjunctions (say,
$\mathbf{Set} \rightleftarrows \mathbf{Mon}$ itself) give more. The
Eilenberg–Moore category is universal among them from above: every inducing
adjunction maps into it.

> **Theorem (Comparison).** Let $F' : \mathcal{A} \rightleftarrows \mathcal{B} : G'$
> be any adjunction inducing the monad $\mathbb{T}$ on $\mathcal{A}$, with counit
> $\varepsilon'$. There is a unique **comparison functor**
> $\Phi : \mathcal{B} \to \mathcal{A}^{\mathbb{T}}$ with
> $U \circ \Phi = G'$ and $\Phi \circ F' = F$, given on objects by
>
> $$
> \Phi(B) = \big(G'B,\; G'\varepsilon'_B\big).
> $$

The structure map $G'\varepsilon'_B : TG'B = G'F'G'B \to G'B$ evaluates by the
counit; its algebra axioms follow from the triangle identities and naturality.
The comparison functor measures how close $\mathcal{B}$ is to being the
category of algebras.

> **Definition (Monadic functor).** A functor $G' : \mathcal{B} \to \mathcal{A}$
> is **monadic** if it has a left adjoint and the comparison functor
> $\Phi : \mathcal{B} \to \mathcal{A}^{\mathbb{T}}$ of the induced monad is an
> equivalence of categories.

Monadicity is the precise sense in which a category "is algebraic over" a base.
The forgetful functors from $\mathbf{Mon}$, $\mathbf{Grp}$, and $R\text{-}\mathbf{Mod}$
to $\mathbf{Set}$ are monadic — that is the content of Linton's theorem read
through the comparison functor. The forgetful functor
$\mathbf{Top} \to \mathbf{Set}$ has a left adjoint (the discrete-space functor)
but is not monadic: its induced monad is the identity, whose algebras are just
sets, and $\mathbf{Top} \not\simeq \mathbf{Set}$. A topology is structure but
not algebraic structure, and monadicity detects the difference.

$$
% caption: Any adjunction inducing $T$ factors through the algebras: the
% comparison functor sends $B$ to the algebra $(G'B,\ G'\varepsilon'_B)$, and
% commutes with both forgetful sides ($G$ in the figure stands for $G'$;
% $\mathbf{A}$, $\mathbf{B}$ for the categories $\mathcal{A}$, $\mathcal{B}$).
\begin{tikzpicture}[>=stealth, font=\small]
  \definecolor{acc}{HTML}{4A6FA5}
  \node[draw, minimum width=26mm, minimum height=10mm] (b)  at (0,2.6)   {$\mathbf{B}$};
  \node[draw, minimum width=26mm, minimum height=10mm] (em) at (6.2,2.6) {$\mathbf{A}^{T}$};
  \node[draw, minimum width=26mm, minimum height=10mm] (a)  at (3.1,0)   {$\mathbf{A}$};
  \draw[->, acc, thick] (b) -- (em) node[midway, above] {comparison};
  \draw[->, acc, thick] (b) -- (a)  node[midway, below left] {$G$};
  \draw[->, acc, thick] (em) -- (a) node[midway, below right] {$U$};
\end{tikzpicture}
$$

## Splitting an adjunction through its algebras

The factorization theorems recast the relationship between a monad and its
sources. Given any adjunction $F' \dashv G'$ inducing $\mathbb{T}$:

- the **monad** $\mathbb{T} = (G'F', \eta, G'\varepsilon' F')$ lives on
  $\mathcal{A}$ and encodes the round trip;
- the **Eilenberg–Moore category** $\mathcal{A}^{\mathbb{T}}$ reconstructs from
  $\mathbb{T}$ alone a canonical codomain, the largest one in a precise sense;
- the **comparison functor** $\Phi$ places the original $\mathcal{B}$ inside
  it.

Barr & Wells note a cultural split over this construction: in mathematics the
Eilenberg–Moore category has been the more important of the two factorizations,
while in computer science the
[Kleisli category](/category-theory/monads-algebras/kleisli-and-programming)
dominates.[^bw-culture] The mathematical uses run through monadicity: proving a
category is algebraic transfers limits, colimits, and exactness properties
wholesale from the base. The computing uses run through free algebras and
substitution, and the Kleisli category is the category of those free algebras.

[^bw-em]: **Barr & Wells**, _Category Theory for Computing Science_, §14.4.2 — Eilenberg–Moore algebras: the definition of a $\mathbb{T}$-algebra by the two commuting diagrams, and the category $\mathcal{A}^{\mathbb{T}}$.
[^bw-def]: **Barr & Wells**, §14.1.3 vs §14.4.2 — an algebra for an endofunctor is any $a : TA \to A$; a triple algebra is one satisfying the unit and associativity diagrams.
[^bw-listalg]: **Barr & Wells**, §14.4.5 Exercise 3 — algebras for the Kleene-closure (list) triple are precisely monoids, and algebra homomorphisms are monoid homomorphisms.
[^bw-linton]: **Barr & Wells**, §14.4.3 (remark) — Linton's theorem: every equationally defined category of one-sorted algebraic structures is the category of Eilenberg–Moore algebras for a triple on $\mathbf{Set}$.
[^bw-emprop]: **Barr & Wells**, §14.4.3 (Proposition) — $F A = (TA, \mu A)$ is left adjoint to the underlying functor $U$, and the associated triple is $\mathbb{T}$.
[^bw-culture]: **Barr & Wells**, §14.4.2 — "In mathematics, this construction has been much more interesting than the Kleisli construction, but in computer science it has been quite the opposite."
