余密度单子 [余密度单子]
余密度单子 [余密度单子]
定义
函子 $f\colon \mathcal C \to \mathcal D$ 的余密度单子 (codensity monad) 是 $f$ 沿着 $f$ 自身的右 Kan 扩张 $f_* f \colon \mathcal D \to \mathcal D$, $$ f_* f (d) = \operatorname{lim}_{d \to f(c)} f(c). $$
由 Kan 扩张的万有性质, 对 $\mathcal C$ 的任意自函子 $F$, 自然变换 $F \to f_* f$ 等同于自然变换 $F\circ f \to f$. 故余密度单子又叫自同态单子, 是万有的作用于 $f$ 上的单子.
例
超滤单子
超滤单子 $\beta\colon \mathsf{Set} \to \mathsf{Set}$ 是 $\mathsf{Fin} \hookrightarrow \mathsf{Set}$ 的余密度单子, $$ \beta X = \operatorname{lim}_{S\to X,S\in\mathsf{Fin}}S. $$
自同态单子
对象 $c\in\mathcal C$ 的自同态单子 $\operatorname{End}(c)$ 是 $c\colon 1 \to\mathcal C$ 的余密度单子.
$$ \operatorname{End}(c)(x) = \operatorname{lim}_{x\to c} c = c^{\operatorname{Hom}(x,c)}. $$
自同态单子可以用来定义单子上的代数: 对任意单子 $T$, 对象 $c$ 上的 $T$-代数结构等同于单子同态 (即 $\mathsf{End}(\mathcal C)$ 中的结合代数同态) $$ T \to \operatorname{End}(c). $$
自同态单子在计算机科学中又叫接续单子 (continuation monad) $\operatorname{Cont}(c)$, 因为 $\operatorname{Cont}(c)(x)$ 的元素相当于输入 “后续” $x\to c$, 输出结果 $c$ 的过程.