module Cat.CartesianClosed.Cont
{o ℓ} {C : Precategory o ℓ} (cart : Cartesian-category C)
(cc : Cartesian-closed C cart)
where
open Cartesian-category cart
open Cartesian-closed cc
open S cart cc
The continuation monad🔗
We show that, in a Cartesian closed category for any object the functor is adjoint to itself on the right — meaning that its left adjoint is its opposite functor.
_] : Ob → Functor (C ^op) C
[-,_] S = Bifunctor.Left ([-,-] C cart cc) S [-,
The proof boils down to noticing that we have an isomorphism natural in all three variables, but we write a proof in components as an application of the solver for CCCs. We define the adjunction mapping first in terms of formal morphisms, and then obtain the actual function as its denotation.
: ∀ S → opFʳ [-, S ] ⊣ [-, S ]
maps-into-self-adjoint = hom-iso→adjoints tr eqv nat where
maps-into-self-adjoint S : ∀ {x y} → Mor y (x `⇒ ` S) → Mor x (y `⇒ ` S)
`tr = `ƛ (`ev `∘ (f `∘ `π₂ `, `π₁))
`tr f
: ∀ {x y} → Hom y [ x , S ] → Hom x [ y , S ]
tr {x} {y} f = ⟦ `tr {x = ` x} {y = ` y} (` f) ⟧ᵐ tr
The proofs that this function is invertible and that it is natural in both and are all applications of the solver.
: ∀ {x y} → is-equiv (tr {x} {y})
eqv {x} {y} = is-iso→is-equiv record where
eqv = tr
from = solve (`tr (`tr {x = ` x} {` y} (` m))) (` m) refl
linv m = solve (`tr (`tr {x = ` y} {` x} (` m))) (` m) refl
rinv m
abstract
: hom-iso-natural {L = opFʳ [-, S ]} {R = [-, S ]} tr
nat {a} {b} {c} {d} g h x =
nat let
: Mor (` c) (` d) ; `h = ` h
`h : Mor (` b) (` a) ; `g = ` g
`g in solve
(`tr ((`ƛ (`id `∘ `ev `∘ (`π₁ `, `h `∘ `π₂)) `∘ ` x) `∘ `g))
(`ƛ (`id `∘ `ev `∘ (`π₁ `, `g `∘ `π₂)) `∘ `tr (` x) `∘ `h)
refl
Every adjunction generates a monad. We refer to the monad structure on as the ( continuation monad.
: ∀ S → Monad-on ([-, S ] F∘ opFʳ [-, S ])
Continuation-monad = Adjunction→Monad (maps-into-self-adjoint S) Continuation-monad S