definition theorem proof example
A monad algebra (Eilenberg–Moore algebra) for a Monad is an algebra compatible with the monad: the unit law and the multiplication law . The second says is itself an algebra morphism . Monad algebras and algebra morphisms form the Eilenberg–Moore category .
Sources: DaoFP §15.5 (“Monad Algebras”, “Eilenberg-Moore category”, “Kleisli category”); §14.7 (the expression monad
Ex); 7 Sketches §1.4.4 (fixed points of a Closure Operator); Kittenlab Lecture 5 (monoids as algebras).
Intuition. Monads generate expressions, algebras evaluate them; compatibility says evaluating a bare variable returns it (alg . return = id, ruling out alg (Var c) = 'a') and evaluating a flattened nested expression equals evaluating inside first (alg (join mma) = alg (fmap alg mma)). For the free monoid monad, algebras are exactly monoids; for a closure operator on a preorder, algebras are its fixed points.
Theorem (every monad comes from an adjunction). Define , , and (a monad algebra by the monad laws), (an algebra morphism by naturality of ). Take unit and counit (an algebra morphism by the multiplication law); the triangle identities follow from the unit laws. Then on objects and arrows, the unit agrees by construction, and at is . So is generated by (Monads from Adjunctions).
The Kleisli Category is the full subcategory of free algebras ; among adjunctions generating (a 2-category), Kleisli is initial and Eilenberg–Moore terminal.
Docs: Kittenlab Lecture 5
# monad algebras for the list monad are monoids: α : [m] -> m must satisfy the two laws
α_sum(xs) = sum(xs; init=0) # (Int, +, 0)
α_sum([5]) == 5 # unit law: α ∘ η = id
xss = [[1, 2], [3]]
α_sum(reduce(vcat, xss)) == α_sum(map(α_sum, xss)) # multiplication law: α ∘ μ = α ∘ T α
# a non-example: α(xs) = length(xs) fails the unit law (α([5]) = 1 ≠ 5)import Mathlib
open CategoryTheory
#check @CategoryTheory.Monad.Algebra -- A, a : T.obj A ⟶ A, unit, assoc
#check @CategoryTheory.Monad.Algebra.Hom
#check @CategoryTheory.Monad.forget -- U^T : Algebra T ⥤ C
#check @CategoryTheory.Monad.free -- F^T
#check @CategoryTheory.Monad.adj -- free ⊣ forget
#check @CategoryTheory.Monad.algebraFunctorOfMonadHom-- an algebra for the expression monad Ex compatible with return and join
data Ex x = Val Int | Var x | Plus (Ex x) (Ex x) deriving Functor
algChar :: Ex Char -> Char
algChar (Val n) = toEnum n
algChar (Var c) = c -- alg . return = id
algChar (Plus e1 e2) = maximum [algChar e1, algChar e2]
-- monad algebras for [] are Monoids: alg = mconcat