Fiveable

🔢Category Theory Unit 10 Review

QR code for Category Theory practice questions

10.4 Kleisli category and free algebras

10.4 Kleisli category and free algebras

Written by the Fiveable Content Team • Last updated August 2025
Written by the Fiveable Content Team • Last updated August 2025
🔢Category Theory
Unit & Topic Study Guides

Kleisli categories and free algebras are key concepts in understanding monads. Kleisli categories represent monadic computations as morphisms, allowing for easy composition. This simplifies working with monads in practical applications.

Free algebras, on the other hand, provide the most general structure for a given monad. They're closely linked to Kleisli categories through adjunctions, offering a different perspective on monadic structures and their properties.

Kleisli Category

Kleisli category for monads

  • The Kleisli category CT\mathcal{C}_T is constructed from a monad (T,η,μ)(T, \eta, \mu) on a category C\mathcal{C}
    • Objects in CT\mathcal{C}_T are the same as objects in C\mathcal{C} (e.g., sets in the category SetSet)
    • Morphisms f:ABf: A \rightarrow B in CT\mathcal{C}_T are morphisms f:AT(B)f: A \rightarrow T(B) in C\mathcal{C} (e.g., functions f:AList(B)f: A \rightarrow List(B) for the list monad)
  • Composition of morphisms f:ABf: A \rightarrow B and g:BCg: B \rightarrow C in CT\mathcal{C}_T is defined as μCT(g)f\mu_C \circ T(g) \circ f
    • f:AT(B)f: A \rightarrow T(B) and g:BT(C)g: B \rightarrow T(C) are morphisms in C\mathcal{C}
    • T(g):T(B)T(T(C))T(g): T(B) \rightarrow T(T(C)) applies the functor TT to the morphism gg
    • μC:T(T(C))T(C)\mu_C: T(T(C)) \rightarrow T(C) is the multiplication natural transformation of the monad TT
  • Identity morphism idA:AAid_A: A \rightarrow A in CT\mathcal{C}_T is given by the unit natural transformation ηA:AT(A)\eta_A: A \rightarrow T(A) of the monad TT

Kleisli category vs monadic computations

  • The Kleisli category CT\mathcal{C}_T captures the composition of monadic computations
    • Monadic values are represented as morphisms in CT\mathcal{C}_T
      • A morphism f:ABf: A \rightarrow B in CT\mathcal{C}_T corresponds to a computation that takes a value of type AA and returns a monadic value of type T(B)T(B) (e.g., f:AList(B)f: A \rightarrow List(B) for the list monad)
    • Composition of morphisms in CT\mathcal{C}_T uses the multiplication μ\mu of the monad, allowing for sequential composition of monadic computations
  • The Kleisli category provides an abstract and compositional way to work with monadic computations without explicitly dealing with the monadic structure
Kleisli category for monads, Free monads in category theory (part 1)

Free Algebras

Free algebras of monads

  • Given a monad (T,η,μ)(T, \eta, \mu) on a category C\mathcal{C} and an object XX in C\mathcal{C}, a free TT-algebra on XX is a TT-algebra (T(X),μX)(T(X), \mu_X) together with a morphism ηX:XT(X)\eta_X: X \rightarrow T(X)
  • The universal property of free algebras states that for any other TT-algebra (A,h)(A, h) and morphism f:XAf: X \rightarrow A, there exists a unique TT-algebra homomorphism f:(T(X),μX)(A,h)f^*: (T(X), \mu_X) \rightarrow (A, h) such that fηX=ff^* \circ \eta_X = f
  • The free TT-algebra (T(X),μX)(T(X), \mu_X) is the "most general" or "least constrained" TT-algebra that can be constructed from XX
Kleisli category for monads, Bartosz Milewski's Programming Cafe | Category Theory, Haskell, Concurrency, C++

Construction of free algebras

  • For the list monad (List,η,μ)(List, \eta, \mu) on the category SetSet:
    1. Given a set XX, the free algebra on XX is (List(X),μX)(List(X), \mu_X)
      • List(X)List(X) is the set of all finite lists with elements from XX
      • μX:List(List(X))List(X)\mu_X: List(List(X)) \rightarrow List(X) concatenates lists, flattening a list of lists into a single list
    2. The morphism ηX:XList(X)\eta_X: X \rightarrow List(X) maps each element xXx \in X to the singleton list [x][x]
  • The universal property ensures that for any other ListList-algebra (A,h)(A, h) and function f:XAf: X \rightarrow A, there exists a unique ListList-algebra homomorphism f:(List(X),μX)(A,h)f^*: (List(X), \mu_X) \rightarrow (A, h) such that fηX=ff^* \circ \eta_X = f

Free algebras vs Kleisli category

  • Free algebras and the Kleisli category are related through adjunctions
  • The free TT-algebra functor FT:CCTF_T: \mathcal{C} \rightarrow \mathcal{C}_T maps an object XX in C\mathcal{C} to the free TT-algebra (T(X),μX)(T(X), \mu_X) in CT\mathcal{C}_T
  • FTF_T is left adjoint to the forgetful functor UT:CTCU_T: \mathcal{C}_T \rightarrow \mathcal{C}, which maps a TT-algebra (A,h)(A, h) in CT\mathcal{C}_T to its underlying object AA in C\mathcal{C}
  • The adjunction between FTF_T and UTU_T establishes a correspondence between free TT-algebras in CT\mathcal{C}_T and objects in C\mathcal{C}
  • The Kleisli category CT\mathcal{C}_T can be seen as a category of free TT-algebras, where morphisms are TT-algebra homomorphisms between free TT-algebras