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 ccThe 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) SThe 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.
maps-into-self-adjoint : ∀ S → opFʳ [-, S ] ⊣ [-, S ]
maps-into-self-adjoint S = hom-iso→adjoints tr eqv nat where
`tr : ∀ {x y} → Mor y (x `⇒ ` S) → Mor x (y `⇒ ` S)
`tr f = `ƛ (`ev `∘ (f `∘ `π₂ `, `π₁))
tr : ∀ {x y} → Hom y [ x , S ] → Hom x [ y , S ]
tr {x} {y} f = ⟦ `tr {x = ` x} {y = ` y} (` f) ⟧ᵐThe proofs that this function is invertible and that it is natural in both and are all applications of the solver.
eqv : ∀ {x y} → is-equiv (tr {x} {y})
eqv {x} {y} = is-iso→is-equiv record where
from = tr
linv m = solve (`tr (`tr {x = ` x} {` y} (` m))) (` m) refl
rinv m = solve (`tr (`tr {x = ` y} {` x} (` m))) (` m) refl
abstract
nat : hom-iso-natural {L = opFʳ [-, S ]} {R = [-, S ]} tr
nat {a} {b} {c} {d} g h x =
let
`h : Mor (` c) (` d) ; `h = ` h
`g : Mor (` b) (` a) ; `g = ` g
in solve
(`tr ((`ƛ (`id `∘ `ev `∘ (`π₁ `, `h `∘ `π₂)) `∘ ` x) `∘ `g))
(`ƛ (`id `∘ `ev `∘ (`π₁ `, `g `∘ `π₂)) `∘ `tr (` x) `∘ `h)
reflEvery adjunction generates a monad. We refer to the monad structure on as the ( continuation monad.
Continuation-monad : ∀ S → Monad-on ([-, S ] F∘ opFʳ [-, S ])
Continuation-monad S = Adjunction→Monad (maps-into-self-adjoint S)