Ultrafilters as a double dual Given a set $X$, let $\beta X$ denote the set of ultrafilters. The following theorems are known:


*

*$X$ canonically embeds into $\beta X$ (by taking principal ultrafilters);

*If $X$ is finite, then there are no non-principal ultrafilters, so $\beta X = X$.

*If $X$ is infinite, then (assuming choice) we have $|\beta X| = 2^{2^{|X|}}$.


These are reminiscent of similar claims that can be made about vector spaces and double duals:


*

*$V$ canonically embeds into $V^{\star \star}$;

*If $V$ is finite-dimensional, then we have $V = V^{\star \star}$;

*If $V$ is infinite-dimensional, then (assuming choice) we have $\dim(V^{\star \star}) = 2^{2^{\dim(V)}}$.


This suggests that the operation of taking the collection of ultrafilters on a set can be viewed as a double iterate of some 'duality' of sets. Can this be made precise: that is to say, is there some notion of a 'dual' of a set $X$, $\delta X$, such that the following are true?


*

*The double dual $\delta \delta X$ is (canonically isomorphic to) the set $\beta X$ of ultrafilters on $X$;

*If $X$ is finite, then $|\delta X| = |X|$ (but not canonically so);

*If $X$ is infinite, then (assuming choice) $|\delta X| = 2^{|X|}$.


Apart from the tempting analogy between $\beta X$ and $V^{\star \star}$, further evidence for this conjecture is that $\beta$ can be given the structure of a monad (the 'ultrafilter monad'), and monads can be obtained from a pair of adjunctions.
 A: This is a quite standard idea in functional analysis. Let $X$ be any set and let $c_0(X)$ be the space of all functions from $X$ to $\mathbb{C}$ which go to zero at infinity. Then the algebra homomorphisms from $c_0(X)$ to $\mathbb{C}$ are precisely the point evaluations at elements of $X$, i.e., the spectrum of $c_0(X)$ is naturally identified with $X$.
Going to the second dual we get $l^\infty(X)$, the space of all bounded functions from $X$ to $\mathbb{C}$, whose spectrum is naturally identified with $\beta X$.
[deleted an additional comment which wasn't accurate]
A: 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})$. 
