nLab continuation monad

Redirected from "double dualization monads".

Context

Computation

Categorical algebra

Type theory

natural deduction metalanguage, practical foundations

  1. type formation rule
  2. term introduction rule
  3. term elimination rule
  4. computation rule

type theory (dependent, intensional, observational type theory, homotopy type theory)

syntax object language

computational trinitarianism =
propositions as types +programs as proofs +relation type theory/category theory

logicset theory (internal logic of)category theorytype theory
propositionsetobjecttype
predicatefamily of setsdisplay morphismdependent type
proofelementgeneralized elementterm/program
cut rulecomposition of classifying morphisms / pullback of display mapssubstitution
introduction rule for implicationcounit for hom-tensor adjunctionlambda
elimination rule for implicationunit for hom-tensor adjunctionapplication
cut elimination for implicationone of the zigzag identities for hom-tensor adjunctionbeta reduction
identity elimination for implicationthe other zigzag identity for hom-tensor adjunctioneta conversion
truesingletonterminal object/(-2)-truncated objecth-level 0-type/unit type
falseempty setinitial objectempty type
proposition, truth valuesubsingletonsubterminal object/(-1)-truncated objecth-proposition, mere proposition
logical conjunctioncartesian productproductproduct type
disjunctiondisjoint union (support of)coproduct ((-1)-truncation of)sum type (bracket type of)
implicationfunction set (into subsingleton)internal hom (into subterminal object)function type (into h-proposition)
negationfunction set into empty setinternal hom into initial objectfunction type into empty type
universal quantificationindexed cartesian product (of family of subsingletons)dependent product (of family of subterminal objects)dependent product type (of family of h-propositions)
existential quantificationindexed disjoint union (support of)dependent sum ((-1)-truncation of)dependent sum type (bracket type of)
logical equivalencebijection setobject of isomorphismsequivalence type
support setsupport object/(-1)-truncationpropositional truncation/bracket type
n-image of morphism into terminal object/n-truncationn-truncation modality
propositional equalitydiagonal function/diagonal subset/diagonal relationpath space objectidentity type/path type
completely presented setsetdiscrete object/0-truncated objecth-level 2-type/set/h-set
setset with equivalence relationinternal 0-groupoidBishop set/setoid with its pseudo-equivalence relation an actual equivalence relation
equivalence class/quotient setquotientquotient type
inductioncolimitinductive type, W-type, M-type
higher inductionhigher colimithigher inductive type
-0-truncated higher colimitquotient inductive type
coinductionlimitcoinductive type
presettype without identity types
set of truth valuessubobject classifiertype of propositions
domain of discourseuniverseobject classifiertype universe
modalityclosure operator, (idempotent) monadmodal type theory, monad (in computer science)
linear logic(symmetric, closed) monoidal categorylinear type theory/quantum computation
proof netstring diagramquantum circuit
(absence of) contraction rule(absence of) diagonalno-cloning theorem
synthetic mathematicsdomain specific embedded programming language

homotopy levels

semantics

Contents

Idea

In a category with internal homs [−,−][-,-], given an object SS, the continuation monad is the endofunctor X↦[[X,S],S]X \mapsto \big[ [X, S], S\big], together with the unit

X ⟶η [[X,S],S] x ↦ λ(k:[X,S]).k(x) \begin{array}{ccl} X &\overset{\eta}{\longrightarrow}& \big[ [X,S],S \big] \\ x &\mapsto& \lambda\big(k:[X,S]\big).\, k(x) \end{array}

and multiplication

[[[[X,S],S],S],S] ⟶μ [[X,S],S] M ↦ λ(k:[X,S]).M(λ(c:[[X,S],S]).c(k)). \begin{array}{ccl} \big[ \big[ [ [X,S],S ],S \big],S \big] &\overset{\mu}{\longrightarrow}& \big[ [X,S],S\big] \\ M &\mapsto& \lambda\big(k:[X,S]\big).\, M\Big(\lambda\big(c: [ [X,S],S]\big). c(k)\Big) \mathrlap{\,.} \end{array}

In general mathematics this monad is ubiquitous as modelling double dualization (cf. Ex. , Ex. and Rem. below).

In computer science this monad is used to model continuation-passing style of programming, and therefore this is also called the continuation monad. The idea here is that a morphism f:X→Yf \colon X \to Y in the Kleisli category of the continuation monad, hence a morphism in the original category of the form X⟶[[Y,S],S]X\longrightarrow [ [Y,S],S], is much like a map from XX to YY only that instead of “returning” its output directly it instead feeds it into a given function Y→SY \to S which hence continues the computation.

Definition

Setting and notation

Remark

(setting) Throughout, (𝒞,⊗,𝟙)(\mathcal{C}, \otimes, \mathbb{1}) denotes a symmetric closed monoidal category, with internal hom [−,−]:𝒞 op×𝒞→𝒞[-,-] \colon \mathcal{C}^{op} \times \mathcal{C} \to \mathcal{C}, evaluation map ev A,B:[A,B]⊗A→B\mathrm{ev}_{A,B} \colon [A,B] \otimes A \to B, and symmetry σ A,B:A⊗B⟶∼B⊗A\sigma_{A,B} \colon A \otimes B \overset{\sim}{\longrightarrow} B \otimes A. The main example is a cartesian closed category such as Set, where ⊗=×\otimes = \times.

We fix an object

S∈𝒞 S \,\in\, \mathcal{C}

and refer to it as the answer object (or answer type, or result type, in computer science). Morphisms k:X→Sk \colon X \to S, hence (generalized) elements k:[X,S]k : [X,S], are called continuations for XX.

Remark

(λ\lambda-notation) We denote morphisms by terms of the simply typed lambda calculus (in the cartesian case) or of the linear λ \lambda -calculus (in the general symmetric monoidal case), interpreted in 𝒞\mathcal{C} as its internal language:

  • a term tt of type BB in a context of variables x 1:X 1,⋯,x n:X nx_1 \colon X_1, \cdots, x_n \colon X_n denotes a morphism X 1⊗⋯⊗X n→BX_1 \otimes \cdots \otimes X_n \to B;

  • applicationk(x)k(x), for k:[X,S]k \colon [X,S] and x:Xx : X, denotes the evaluation map, ev(k⊗x)\mathrm{ev}(k \otimes x);

  • abstraction λ(x:X).t\lambda (x : X).\, t denotes the adjunct (“currying”) of the morphism denoted by tt;

  • for terms a:Aa : A and x:Xx : X in disjoint contexts, a⊗xa \otimes x denotes their tensor product, a term of type A⊗XA \otimes X; and a morphism out of a tensor product A⊗XA \otimes X is specified by a term tt in context a:A,x:Xa : A,\, x : X, written as a⊗x↦ta \otimes x \,\mapsto\, t. (In the cartesian case, a⊗xa \otimes x is just the pair (a,x)(a,x).)

By the universal property of the internal hom, these terms satisfy β \beta -reduction (λx.t)(a)=t[a/x](\lambda x.\, t)(a) = t[a/x] and η \eta -reduction λx.k(x)=k\lambda x.\, k(x) = k.

In the cartesian case this is equivalently the usual notation in terms of generalized elements. In the general symmetric monoidal case it is legitimate here because all terms below use each variable — whether bound or free in the context — exactly once (Rem. ).

We also write k∘f:=λx.k(f(x))k \circ f \,:=\, \lambda x.\, k\big(f(x)\big).

The dualization adjunction

Proposition

(dualization is self-adjoint on the right) The functor of dualization into SS,

[−,S]:𝒞 op⟶𝒞,(X⟶fY)↦([Y,S]⟶[f,S][X,S],k↦k∘f), [-,S] \;\colon\; \mathcal{C}^{op} \longrightarrow \mathcal{C} \,, \;\;\;\;\;\;\; \big( X \overset{f}{\longrightarrow} Y \big) \;\;\mapsto\;\; \Big( [Y,S] \overset{[f,S]}{\longrightarrow} [X,S] \,, \;\; k \mapsto k \circ f \Big) \,,

is right adjoint to its own opposite functor:

𝒞 op⊥⟶[−,S]⟵[−,S] op𝒞. \mathcal{C}^{op} \underoverset {\underset{[-,S]}{\longrightarrow}} {\overset{[-,S]^{op}}{\longleftarrow}} {\bot} \mathcal{C} \,.

The hom-isomorphism of this adjunction is the composite of natural isomorphisms

𝒞 op([X,S],A)=𝒞(A,[X,S])≃𝒞(A⊗X,S)≃𝒞(σ X,A,S)𝒞(X⊗A,S)≃𝒞(X,[A,S]), \mathcal{C}^{op}\big([X,S],\, A\big) \;=\; \mathcal{C}\big(A,\, [X,S]\big) \;\simeq\; \mathcal{C}\big(A \otimes X,\, S\big) \underset{ \mathcal{C}(\sigma_{X,A},\, S) }{\simeq} \mathcal{C}\big(X \otimes A,\, S\big) \;\simeq\; \mathcal{C}\big(X,\, [A,S]\big) \,,

which in λ\lambda-notation (Rem. ) is “swapping the arguments”:

(A⟶ϕ[X,S])↦(X⟶ϕ˜[A,S]),ϕ˜:=λ(x:X).λ(a:A).ϕ(a)(x). \Big( A \overset{\phi}{\longrightarrow} [X,S] \Big) \;\;\;\; \mapsto \;\;\;\; \Big( X \overset{\widetilde{\phi}}{\longrightarrow} [A,S] \Big) \,, \;\;\;\;\;\; \widetilde{\phi} \;:=\; \lambda (x : X).\, \lambda (a : A).\, \phi(a)(x) \,.

This bijection is its own inverse: ϕ˜˜=ϕ\widetilde{\widetilde{\phi}} = \phi.

Proof

Each of the displayed bijections is natural in X∈𝒞X \in \mathcal{C} and in A∈𝒞 opA \in \mathcal{C}^{op}; the outer two by the definition of the internal hom, and the middle one by naturality of the symmetry. That the composite is an involution follows from σ A,X∘σ X,A=id\sigma_{A,X} \circ \sigma_{X,A} = \mathrm{id}, or directly from the λ\lambda-formula.

Remark

(unit and counit) The adjunction unit of Prop. at X∈𝒞X \in \mathcal{C} is the image of id [X,S]\mathrm{id}_{[X,S]} under the hom-isomorphism, which is the canonical map into the double dual:

η X:X⟶[[X,S],S],η X:=λ(x:X).λ(k:[X,S]).k(x), \eta_X \;\colon\; X \longrightarrow [ [X,S],S] \,, \;\;\;\;\;\;\; \eta_X \;:=\; \lambda (x : X).\, \lambda (k : [X,S]).\, k(x) \,,

namely the adjunct of X⊗[X,S]⟶σ[X,S]⊗X⟶evSX \otimes [X,S] \overset{\sigma}{\longrightarrow} [X,S] \otimes X \overset{\mathrm{ev}}{\longrightarrow} S.

Since the hom-isomorphism is its own inverse, the adjunction counit at A∈𝒞 opA \in \mathcal{C}^{op} is, regarded as a morphism in 𝒞\mathcal{C}, the same kind of map, namely η A:A→[[A,S],S]\eta_A \colon A \to [ [A,S],S]. Accordingly, both triangle identities of the adjunction reduce to one and the same identity in 𝒞\mathcal{C}, saying that the single dual is a retract of the triple dual:

[η A,S]∘η [A,S]=id [A,S]for allA∈𝒞. [\eta_A, S] \circ \eta_{[A,S]} \;=\; \mathrm{id}_{[A,S]} \;\;\;\;\;\; \text{for all}\; A \in \mathcal{C} \,.

In λ\lambda-notation:

k↦λ(c:[[A,S],S]).c(k)↦λ(a:A).(λc.c(k))(η A(a))=λa.η A(a)(k)=λa.k(a)=k. k \;\;\mapsto\;\; \lambda (c : [ [A,S],S]).\, c(k) \;\;\mapsto\;\; \lambda (a : A).\, \big(\lambda c.\, c(k)\big)\big(\eta_A(a)\big) \;=\; \lambda a.\, \eta_A(a)(k) \;=\; \lambda a.\, k(a) \;=\; k \,.

The continuation monad

Definition

(continuation monad) The continuation monad (or double dualization monad) on 𝒞\mathcal{C} with answer object SS is the monad (D,η,μ)(D, \eta, \mu) induced by the adjunction of Prop. , hence with

D:=[−,S]∘[−,S] op:𝒞⟶𝒞,η:=adjunction unit,μ:=[−,S]ϵ[−,S] op. D \;:=\; [-,S] \circ [-,S]^{op} \;\colon\; \mathcal{C} \longrightarrow \mathcal{C} \,, \;\;\;\;\;\;\; \eta \;:=\; \text{adjunction unit} \,, \;\;\;\;\;\;\; \mu \;:=\; [-,S] \, \epsilon \, [-,S]^{op} \,.

Explicitly, the components are as follows:

The underlying endofunctor is

D(X)=[[X,S],S],D(f)=[[f,S],S], D(X) \;=\; [ [X,S],S] \,, \;\;\;\;\;\;\; D(f) \;=\; [ [f,S],S] \,,

hence for f:X→Yf \colon X \to Y:

D(f):[[X,S],S]⟶[[Y,S],S],ϕ↦λ(k:[Y,S]).ϕ(k∘f). D(f) \;\colon\; [ [X,S],S] \longrightarrow [ [Y,S],S] \,, \;\;\;\;\;\;\; \phi \;\mapsto\; \lambda (k : [Y,S]).\, \phi(k \circ f) \,.

The unit is the canonical map into the double dual (Rem. ):

η X:X⟶[[X,S],S],x↦λ(k:[X,S]).k(x). \eta_X \;\colon\; X \longrightarrow [ [X,S],S] \,, \;\;\;\;\;\;\; x \;\mapsto\; \lambda (k : [X,S]).\, k(x) \,.

The multiplication is the dual of the unit at [X,S][X,S]:

μ X:=[η [X,S],S]:[[[[X,S],S],S],S]⟶[[X,S],S], \mu_X \;:=\; [\eta_{[X,S]},\, S] \;\colon\; [ [ [ [X,S],S],S],S] \longrightarrow [ [X,S],S] \,,

hence it is given by precomposition with η [X,S]\eta_{[X,S]},

μ X(M)=M∘η [X,S], \mu_X(M) \;=\; M \circ \eta_{[X,S]} \,,

which in λ\lambda-notation reads:

μ X(M)=λ(k:[X,S]).M(λ(c:[[X,S],S]).c(k)). \mu_X(M) \;=\; \lambda (k : [X,S]).\, M\Big( \lambda (c : [ [X,S],S]).\, c(k) \Big) \,.

Remark

(unwinding the multiplication) In the λ\lambda-term for μ X\mu_X in Def. the subterms have the following types:

k : [X,S] c : [[X,S],S] c(k) : S λc.c(k)=η [X,S](k) : [[[X,S],S],S] M : [[[[X,S],S],S],S] M(λc.c(k)) : S λk.M(λc.c(k)) : [[X,S],S] \array{ \arrayopts{\colalign{right center left}} k &:& [X,S] \\ c &:& [ [X,S],S] \\ c(k) &:& S \\ \lambda c.\, c(k) \;=\; \eta_{[X,S]}(k) &:& [ [ [X,S],S],S] \\ M &:& [ [ [ [X,S],S],S],S] \\ M\big(\lambda c.\, c(k)\big) &:& S \\ \lambda k.\, M\big(\lambda c.\, c(k)\big) &:& [ [X,S],S] }

In words: μ X(M)\mu_X(M) is the functional on continuations which, given a continuation k:X→Sk \colon X \to S, evaluates MM on the “evaluation at kk”-functional

η [X,S](k)=λ(c:[[X,S],S]).c(k), \eta_{[X,S]}(k) \;=\; \lambda \big(c : [ [X,S],S]\big).\, c(k) \,,

hence:

μ X(M)(k)=M(η [X,S](k)). \mu_X(M)(k) \;=\; M\big(\eta_{[X,S]}(k)\big) \mathrlap{\,.}

Proposition

(monad laws) The data in Def. satisfies the monad axioms.

Proof

Abstractly, this is a special case of the general fact that every adjunction L⊣RL \dashv R induces a monad (RL,η,RϵL)(R L, \eta, R \epsilon L).

Concretely, in terms of the one triangle identity from Rem. , of the contravariant functoriality [g,S]∘[h,S]=[h∘g,S][g,S] \circ [h,S] = [h \circ g, S] and of naturality of η\eta:

Left unit law. By the triangle identity for A=[X,S]A = [X,S]:

μ X∘η DX=[η [X,S],S]∘η [[X,S],S]=id DX. \mu_X \circ \eta_{D X} \;=\; [\eta_{[X,S]}, S] \circ \eta_{[ [X,S],S]} \;=\; \mathrm{id}_{D X} \,.

Right unit law. By the triangle identity for A=XA = X:

μ X∘D(η X)=[η [X,S],S]∘[[η X,S],S]=[[η X,S]∘η [X,S],S]=[id [X,S],S]=id DX. \mu_X \circ D(\eta_X) \;=\; [\eta_{[X,S]},S] \circ \big[ [\eta_X, S], S\big] \;=\; \Big[ [\eta_X,S] \circ \eta_{[X,S]},\, S\Big] \;=\; [\mathrm{id}_{[X,S]}, S] \;=\; \mathrm{id}_{D X} \,.

Associativity. We have

μ X∘μ DX=[η [DX,S]∘η [X,S],S]andμ X∘D(μ X)=[[μ X,S]∘η [X,S],S], \mu_X \circ \mu_{D X} \;=\; \big[ \eta_{[D X,S]} \circ \eta_{[X,S]} ,\, S \big] \;\;\;\;\;\; \text{and} \;\;\;\;\;\; \mu_X \circ D(\mu_X) \;=\; \big[ [\mu_X, S] \circ \eta_{[X,S]} ,\, S \big] \,,

and these agree: since [μ X,S]=[[η [X,S],S],S]=D(η [X,S])[\mu_X,S] = \big[ [\eta_{[X,S]},S],S\big] = D(\eta_{[X,S]}), the equation η [DX,S]∘η [X,S]=D(η [X,S])∘η [X,S]\eta_{[D X,S]} \circ \eta_{[X,S]} = D(\eta_{[X,S]}) \circ \eta_{[X,S]} is the naturality square of η\eta on the morphism η [X,S]:[X,S]→[DX,S]\eta_{[X,S]} \colon [X,S] \to [D X, S].

Alternatively, in λ\lambda-notation, using only β\beta- and η\eta-reduction (for associativity, both sides reduce to the same term):

μ X(η DX(ϕ)) = λk.(λc.c(k))(ϕ)=λk.ϕ(k)=ϕ μ X(D(η X)(ϕ)) = λk.ϕ(λx.η X(x)(k))=λk.ϕ(λx.k(x))=ϕ μ X(μ DX(ℳ)) = λk.ℳ(λC.C(λc.c(k))) μ X(D(μ X)(ℳ)) = λk.ℳ(λC.μ X(C)(k))=λk.ℳ(λC.C(λc.c(k))). \array{ \arrayopts{\colalign{right center left}} \mu_X\big(\eta_{D X}(\phi)\big) &=& \lambda k.\, \big(\lambda c.\, c(k)\big)(\phi) \;=\; \lambda k.\, \phi(k) \;=\; \phi \\ \mu_X\big(D(\eta_X)(\phi)\big) &=& \lambda k.\, \phi\big(\lambda x.\, \eta_X(x)(k)\big) \;=\; \lambda k.\, \phi\big(\lambda x.\, k(x)\big) \;=\; \phi \\ \mu_X\big(\mu_{D X}(\mathcal{M})\big) &=& \lambda k.\, \mathcal{M}\Big(\lambda C.\, C\big(\lambda c.\, c(k)\big)\Big) \\ \mu_X\big(D(\mu_X)(\mathcal{M})\big) &=& \lambda k.\, \mathcal{M}\big(\lambda C.\, \mu_X(C)(k)\big) \;=\; \lambda k.\, \mathcal{M}\Big(\lambda C.\, C\big(\lambda c.\, c(k)\big)\Big) \mathrlap{\,.} }

This completes the argument.

Remark

(linearity and the role of the symmetry) In each of the λ\lambda-terms on this page every variable, whether bound or free in the context, occurs exactly once. Therefore these terms make sense in the internal linear type theory of any symmetric closed monoidal category: they use neither duplication nor deletion of variables, which is why the definition does not require 𝒞\mathcal{C} to be cartesian (see Melliès & Tabareau 2007).

On the other hand, the symmetry σ\sigma is used, if implicitly: it is the exchange rule which allows to form k(x)k(x) in the context x:X,k:[X,S]x : X,\, k : [X,S], as in the definition of η X\eta_X. In a non-symmetric biclosed monoidal category, writing [X,−] r[X,-]_r for the right adjoint of (−)⊗X(-) \otimes X and [X,−] l[X,-]_l for that of X⊗(−)X \otimes (-), the hom-isomorphism of Prop. is instead

𝒞(A,[X,S] r)≃𝒞(A⊗X,S)≃𝒞(X,[A,S] l), \mathcal{C}\big(A,\, [X,S]_r\big) \;\simeq\; \mathcal{C}\big(A \otimes X,\, S\big) \;\simeq\; \mathcal{C}\big(X,\, [A,S]_l\big) \,,

so that one has to alternate between the two one-sided internal homs: X↦[[X,S] r,S] lX \mapsto \big[ [X,S]_r, S\big]_l.

Equivalent formulations

Proposition

(Kleisli triple / bind form) In terms of Kleisli extension, the continuation monad (Def. ) is given by the unit η\eta together with the operation which sends a Kleisli morphism f:X→[[Y,S],S]f \colon X \to [ [Y,S],S] to

f *:=μ Y∘D(f):[[X,S],S]⟶[[Y,S],S],ϕ↦λ(k:[Y,S]).ϕ(λ(x:X).f(x)(k)). f^\ast \;:=\; \mu_Y \circ D(f) \;\colon\; [ [X,S],S] \longrightarrow [ [Y,S],S] \,, \;\;\;\;\;\;\; \phi \;\mapsto\; \lambda (k : [Y,S]).\, \phi\big( \lambda (x : X).\, f(x)(k) \big) \,.

Conversely, the multiplication and the functor are recovered as

μ X=(id DX) *,D(f)=(η Y∘f) *, \mu_X \;=\; \big(\mathrm{id}_{D X}\big)^\ast \,, \;\;\;\;\;\;\; D(f) \;=\; \big(\eta_Y \circ f\big)^\ast \,,

and the composite of Kleisli morphisms f:X→DYf \colon X \to D Y and g:Y→DZg \colon Y \to D Z is

g *∘f=λ(x:X).λ(k:[Z,S]).f(x)(λ(y:Y).g(y)(k)). g^\ast \circ f \;=\; \lambda (x : X).\, \lambda (k : [Z,S]).\, f(x)\big( \lambda (y : Y).\, g(y)(k) \big) \,.

This is the form in which the continuation monad appears in Moggi (1991), Ex. 1.1. In Haskell-notation (ignoring that the standard libraries define Cont r as ContT r Identity, with ContT a newtype):

type Cont r a = (a -> r) -> r

return x  = \k -> k x               -- unit
m >>= f   = \k -> m (\x -> f x k)   -- Kleisli extension
join mm   = \k -> mm (\m -> m k)    -- multiplication

Proposition

(Kleisli morphisms as continuation transformers) Under the hom-isomorphism of Prop. , Kleisli morphisms f:X→[[Y,S],S]f \colon X \to [ [Y,S],S] correspond to morphisms

f˜:[Y,S]⟶[X,S],k↦λ(x:X).f(x)(k), \widetilde{f} \;\colon\; [Y,S] \longrightarrow [X,S] \,, \;\;\;\;\;\;\; k \;\mapsto\; \lambda (x : X).\, f(x)(k) \,,

which turn continuations of the output into continuations of the input. This correspondence is compatible with composition, in that

η X˜=id [X,S],g *∘f˜=f˜∘g˜. \widetilde{\eta_X} \;=\; \mathrm{id}_{[X,S]} \,, \;\;\;\;\;\;\; \widetilde{ g^\ast \circ f } \;=\; \widetilde{f} \circ \widetilde{g} \,.

Hence the Kleisli category of the continuation monad is equivalent to the opposite of the full subcategory of 𝒞\mathcal{C} on the objects of the form [X,S][X,S], via X↦[X,S]X \mapsto [X,S] and f↦f˜f \mapsto \widetilde{f}. (This is an instance of the general fact that the Kleisli category of the monad induced by an adjunction is equivalent to the full image of the left adjoint.)

In these terms, Kleisli extension and multiplication are just dualization of continuation transformers:

f *=[f˜,S],μ X=[id DX˜,S]=[η [X,S],S]. f^\ast \;=\; [\widetilde{f},\, S] \,, \;\;\;\;\;\;\; \mu_X \;=\; \big[\widetilde{\mathrm{id}_{D X}},\, S\big] \;=\; [\eta_{[X,S]},\, S] \,.

Remark

(as a codensity monad) The continuation monad is the (𝒞\mathcal{C}-enriched) codensity monad of the functor 𝟙→𝒞\mathbb{1} \to \mathcal{C} which picks the object SS, since the right Kan extension of SS along itself is the cotensor

Ran SS(X)≃{[X,S],S}=[[X,S],S]. \mathrm{Ran}_S S \,(X) \;\simeq\; \big\{ [X,S],\, S \big\} \;=\; [ [X,S],S] \,.

For 𝒞=\mathcal{C} = Set this is the familiar X↦S (S X)X \mapsto S^{(S^X)}.

Codensity monads of inclusions of full subcategories of “small” objects are closely related: the codensity monad of FinSet ↪\hookrightarrow Set is the ultrafilter monad, which is a submonad of the continuation monad on SetSet with S={0,1}S = \{0,1\} (Ex. ); and the codensity monad of the inclusion of finite-dimensional vector spaces into all vector spaces is the continuation monad of Ex. itself (see Leinster (2013)).

Strength

Proposition

(strength) The continuation monad is a strong monad, with tensorial strength

t A,X:A⊗[[X,S],S]⟶[[A⊗X,S],S],a⊗ϕ↦λ(k:[A⊗X,S]).ϕ(λ(x:X).k(a⊗x)); t_{A,X} \;\colon\; A \otimes [ [X,S],S] \longrightarrow [ [A \otimes X, S], S] \,, \;\;\;\;\;\;\; a \otimes \phi \;\mapsto\; \lambda (k : [A \otimes X, S]).\, \phi\big( \lambda (x : X).\, k(a \otimes x) \big) \,;

equivalently (Kock (1972)) it is a 𝒞\mathcal{C}-enriched monad, with action on internal homs

[X,Y]⟶[DX,DY],f↦λ(ϕ:DX).λ(k:[Y,S]).ϕ(k∘f). [X,Y] \longrightarrow \big[ D X,\, D Y \big] \,, \;\;\;\;\;\;\; f \;\mapsto\; \lambda (\phi : D X).\, \lambda (k : [Y,S]).\, \phi(k \circ f) \,.

Remark

(non-commutativity) The continuation monad is (in general) not a commutative monad: The two maps DX⊗DY→D(X⊗Y)D X \otimes D Y \to D(X \otimes Y) induced by the strength and its mirror image are

ϕ⊗ψ↦λk.ϕ(λx.ψ(λy.k(x⊗y)))andϕ⊗ψ↦λk.ψ(λy.ϕ(λx.k(x⊗y))), \phi \otimes \psi \;\mapsto\; \lambda k.\, \phi\Big(\lambda x.\, \psi\big(\lambda y.\, k(x \otimes y)\big)\Big) \;\;\;\;\;\;\; \text{and} \;\;\;\;\;\;\; \phi \otimes \psi \;\mapsto\; \lambda k.\, \psi\Big(\lambda y.\, \phi\big(\lambda x.\, k(x \otimes y)\big)\Big) \,,

which differ in the order in which ϕ\phi and ψ\psi get to act on the continuation (“evaluation order”). For example, in 𝒞=\mathcal{C} = Set with S={0,1}S = \{0,1\} and X=Y=*X = Y = \ast, let ϕ\phi and ψ\psi be the constant functionals with value 00 and 11, respectively: then the first map gives the constant functional with value 00, the second the one with value 11.

Examples

First examples

Example

(double powerset) For 𝒞=\mathcal{C} = Set and S={0,1}S = \{0,1\}, identify maps X→{0,1}X \to \{0,1\} with subsets A⊂XA \subset X (via their characteristic functions). Then DX≃PPXD X \simeq P P X is the set of families 𝒜\mathcal{A} of subsets of XX, and the structure maps of Def. become:

η X(x) = {A⊂X|x∈A} D(f)(𝒜) = {B⊂Y|f −1(B)∈𝒜} μ X(𝔐) = {A⊂X|{𝒜∈PPX|A∈𝒜}∈𝔐}. \array{ \arrayopts{\colalign{right center left}} \eta_X(x) &=& \big\{ A \subset X \,\big\vert\, x \in A \big\} \\ D(f)(\mathcal{A}) &=& \big\{ B \subset Y \,\big\vert\, f^{-1}(B) \in \mathcal{A} \big\} \\ \mu_X(\mathfrak{M}) &=& \Big\{ A \subset X \,\Big\vert\, \big\{ \mathcal{A} \in P P X \,\vert\, A \in \mathcal{A} \big\} \in \mathfrak{M} \Big\} \mathrlap{\,.} }

Elements of PPXP P X may be thought of as generalized quantifiers on XX, for instance ∀ X={X}\forall_X = \{X\} and ∃ X={A⊂X|A≠∅}\exists_X = \{ A \subset X \,\vert\, A \neq \varnothing\}, while η X(x)\eta_X(x) is the principal ultrafilter at xx (“evaluation at xx”).

Restricting to upward closed families, to filters, or to ultrafilters yields submonads, the last one being the ultrafilter monad, whose algebras are the compact Hausdorff spaces (see Leinster (2013) and Rem. below).

Example

(double dual vector spaces) For 𝒞=Vect 𝕂\mathcal{C} = \mathrm{Vect}_{\mathbb{K}} the category of vector spaces over a field 𝕂\mathbb{K}, with ⊗\otimes the tensor product of vector spaces, and with S=𝕂S = \mathbb{K} the ground field, the continuation monad is

V↦V ** V \;\mapsto\; V^{\ast\ast}

with η V:V→V **\eta_V \colon V \to V^{\ast\ast} the canonical map of a vector space into its double dual (which is injective by the existence of bases, invoking the axiom of choice for infinite-dimensional VV), and with multiplication

μ V=[η V *,𝕂]:V ****⟶V ** \mu_V \;=\; [\eta_{V^\ast}, \mathbb{K}] \;\colon\; V^{\ast\ast\ast\ast} \longrightarrow V^{\ast\ast}

the dual linear map of the canonical inclusion η V *:V *↪V ***\eta_{V^\ast} \colon V^\ast \hookrightarrow V^{\ast\ast\ast} (as in Def. ). This is an example where 𝒞\mathcal{C} is not cartesian (cf. Rem. ). On finite-dimensional vector spaces the unit η\eta is an isomorphism.

Further examples

Remark

(Stone-Čech compactification)

The Stone-Čech compactification functor β:Top→CpHaus\beta \colon Top \to CpHaus is the universal way to map a topological space into a compact Hausdorff space, and it is a form of double dualization into the unit interval [0,1][0,1], which is a cogenerator in the category of compact Hausdorff spaces (by Urysohn's lemma): For any topological space XX, βX\beta X is homeomorphic to the closure of the image of the map

X ⟶ [0,1] C(X,[0,1]) x ↦ (h↦h(x)) \begin{array}{ccc} X &\longrightarrow& [0,1]^{C(X,[0,1])} \\ x &\mapsto& \big(h \mapsto h(x)\big) \end{array}

into the product topological space of copies of [0,1][0,1] indexed by the set C(X,[0,1])C(X,[0,1]) of continuous functions — this map being the evident analog of the unit η X\eta_X (Def. ), with the internal hom replaced by the set of continuous functions.

Composing β\beta with the inclusion functor ι:CpHaus↪Top\iota \colon CpHaus \hookrightarrow Top yields a monad ι∘β\iota \circ \beta on TopTop.

To a topologist this monad is not an instance of the continuation monad of Def. because:

However the definition does not require the category to be cartesian closed. Top is a symmetric monoidal closed category under the tensor product topology: take the largest topology on the product set of XX and YY such that all the constant graph functions are continuous, and endow the hom sets hom(X,Y)hom(X,Y) with the smallest topology such that the point evaluation functions are continuous. With these constructions the evaluation function ev(f,x)=f(x)ev(f,x)=f(x) is continuous. Using that topology the Stone-Cech compactification monad is the double dualization monad into the unit interval, i.e., define betabeta as the double dual into the unit interval.

Note that then ι∘β\iota \circ \beta is the codensity monad of the inclusion ι\iota (as for the codensity monad of any right adjoint, see Leinster (2013)), in line with Rem. . Computing the right Kan extension of the inclusion functor along itself one obtains the double dualization monad on Top. (Use the fact that, on compact Haussdorf spaces, the double dual into the unit interval is an isomorphism.)

Further examples are discussed at:

Properties

Algebras

Proposition

(monadicity of dualization over SetSet) On the category of sets, the functor [−,S]:Set op→Set[-,S] \colon\mathbf{Set}^{op}\to \mathbf{Set} is monadic (with left adjoint [−,S] op:Set→Set op[-, S]^{op} \colon \mathbf{Set} \to \mathbf{Set}^{op}) whenever |S|≥2{|S|}\geq 2.

(cf. Hyland, Levy, Plotkin & Power 2007 Prop. 10)

Proof

The following argument uses classical logic, for instance in identifying the subobject classifier of SetSet with the boolean domain 22.

Since [−,S][-,S] has the left adjoint [−,S] op[-,S]^{op} (Prop. ) and Set opSet^{op} has reflexive coequalizers (these being the coreflexive equalizers in SetSet), by Beck’s crude monadicity theorem it suffices to see that [−,S][-,S]

  1. preserves reflexive coequalizers, hence takes coreflexive equalizers in SetSet to coequalizers in SetSet,

  2. reflects isomorphisms.

(The alternative argument of Hyland, Levy, Plotkin & Power 2007, Prop. 10, shows and uses that the image under [−,S][-,S] of a coreflexive equalizer is a split coequalizer.)

Regarding the first point: Say that SS is (internally) injective if [−,S][-, S] takes coreflexive equalizers in SetSet to coequalizers in SetSet. (The coreflexivity cannot be dropped here: For example, the equalizer of the identity and of the swap map τ\tau on 2={0,1}2 = \{0,1\} is ∅↪2\varnothing \hookrightarrow 2, but the coequalizer of [id,2][\mathrm{id},2] and [τ,2][\tau,2] on the 4-element set [2,2][2,2] has 3 elements, while [∅,2][\varnothing,2] has a single element.)

The subobject classifier 22 is injective in this sense, by the proof of Paré’s theorem (for constructing finite colimits in an elementary topos), which shows that the power object functor takes coreflexive equalizers to (split) coequalizers. Since S×(−):Set→SetS \times (-) \colon Set \to Set preserves connected limits such as equalizers (and, as does any functor, coreflexive pairs), it follows that [S×−,2]≅[−,2 S][S \times -, 2] \cong [-, 2^S] takes coreflexive equalizers to coequalizers, i.e., that 2 S2^S is injective, for any SS. Finally, for |S|≥2|S| \geq 2, SS is a retract of 2 S2^S — via the map s↦{s}s \mapsto \{s\} and the map which sends singletons to their element and all other subsets to a fixed element s 0∈Ss_0 \in S — so that the functor [−,S][-,S] is a retract of [−,2 S][-,2^S]; and since a retract of a coequalizer diagram is again a coequalizer diagram, also SS is injective.

Regarding the second point: Since |S|≥2|S| \geq 2, the set 22 is a retract of SS; and since 22 is a cogenerator in SetSet, so is SS, which means that [−,S][-,S] is faithful. But faithful functors reflect monomorphisms and epimorphisms, and in SetSet every morphism which is both is an isomorphism. Hence [−,S][-, S] reflects isomorphisms.

Remark

(algebras as complete atomic Boolean algebras) Thus, for |S|≥2|S| \geq 2, the Eilenberg-Moore algebras of the continuation monad on SetSet are equivalent to complete atomic Boolean algebras, as the category of these is equivalent to the opposite of the category of sets. (For |S|≤1|S| \leq 1 the continuation monad degenerates: For S=*S = \ast it is constant on the point, while for S=∅S = \varnothing it sends ∅\varnothing to itself and every other set to the point.)

Remark

(monadic in multiple ways) This illustrates the fact that a category can be monadic over Set\mathbf{Set} in multiple ways. In other words, one should not refer to a category CC as monadic over SetSet, unless everyone agrees to which “forgetful functor” U:C→SetU\colon C \to \mathbf{Set} is being considered – better is to refer to a functor as monadic.

References

As a monad in mathematics:

As a monad in computer science:

As a codensity monad:

In the generality of linear type theory as the linear double negation monad:

The characterization of algebras over the continuation monad:

A characterisation of (enriched) monads isomorphic to continuation monads is given in:

  • Christopher Townsend, When are enriched strong monads double exponential monads?, Bulletin of the Belgian Mathematical Society-Simon Stevin 23.2 (2016) 311–319 [doi:10.36045/bbms/1464710120]

Last revised on October 21, 2026 at 00:11:00. See the history of this page for a list of all contributions to it.