This is an elaboration on Todd Trimble's comment about Tom Leinster's lovely posts about codensity monads. I quite like the codensity monad story; here is my preferred way of telling it.

Suppose you have a functor $F : C \to D$. A general question to ask about it is this:

What additional structure, beyond being objects in $D$, do the objects $F(c) \in D$ canonically have, by virtue of having been spit out by $F$?

A simple construction is that the objects $F(c)$ canonically admit an action by the automorphism group $\text{Aut}(F)$ of $F$ as a functor, more or less by definition, and more generally by the endomorphism monoid of $F$. This observation can already be used to motivate Weyl groups and Hecke algebras.

A more elaborate construction is that if $F$ admits a left adjoint $G : D \to C$, then the objects $F(c)$ canonically admit an action by the monad $T = FG : D \to D$, by which I mean they are canonically algebras over this monad. In nice cases (see monadic adjunction and monadicity theorem) this completely characterizes $C$ in terms of $D$ and $T$, for example if $D = \text{Set}$ and $C$ is a typical algebraic category such as groups, rings, modules. A more unusual example here is that $C$ can be compact Hausdorff spaces, and then $T$ is the ultrafilter monad.

But there's an even more general construction than this, which can be motivated in several ways. Here's one. Suppose a monoidal category $M$ acts by endomorphisms on a category $E$, meaning we have a monoidal functor $M \to [E, E]$, where $[E, E]$ is the monoidal category of endofunctors $E \to E$. This is the minimal setup we need to talk about a monoid $m \in M$ acting on an object $e \in E$; see this blog post where I use this setup to motivate the definition of a monad.

Now, given an object $e \in E$, we can ask for the universal monoid in $M$ which acts on $e$, which is an "$M$-internal" notion of the endomorphism monoid of $e$. This monoid $m \in M$, if it exists, is defined by the universal property that maps $n \to m$ of monoids are in natural bijection with actions of $n$ on $e$. If $M = [E, E]$, then this construction, when it exists, recovers the endomorphism monad of $e$. If $E = M$ acting on itself by left multiplication, then this construction, when it exists, recovers the internal endomorphism object of $e$.

In our setting we want to apply this construction to $E = [C, D]$ and $M = [D, D]$, where $[D, D]$ acts on $[C, D]$ by postcomposition. That is, we want a monad $T : D \to D$ which universally acts on a functor $F : C \to D$ in the sense that maps of monads to $T$ are in natural bijection with actions of monads on $F$.

**Claim:** This monad, if it exists, is the codensity monad of $F$.

(I don't have a reference for this, although it's closely related to the definition of the codensity monad as the right Kan extension of $F$ along itself; I remember convincing myself of this a few years ago, around the time I wrote this blog post on monads, and then I never wrote up the details. Welp.)

Now the really fun fact, which Todd Trimble alludes to above, is:

The codensity monad of the inclusion $\text{FinSet} \to \text{Set}$ is the ultrafilter monad, and the codensity monad of the inclusion $\text{FinVect} \to \text{Vect}$ is the double dual monad.

This sets up a lovely analogy between compact Hausdorff spaces (algebras over the ultrafilter monad) and whatever algebras over the double dual monad are; Tom and Todd call them "linearly compact vector spaces" but my preferred terminology here is just "profinite vector spaces," in that the category is precisely $\text{Pro}(\text{FinVect})$.

20more comments