Continuation Monad #
@cite{barker-shan-2014} @cite{charlow-2021}
General-purpose continuation monad, following @cite{barker-shan-2014}.
The type Cont R A := (A → R) → R underlies lifted question types
(LiftedTypes.lean), higher-order dynamic GQs, and
scope-taking expressions generally.
Key definitions #
The continuation monad: (A → R) → R.
An expression of type Cont R A takes a continuation A → R and
produces a result of type R.
Equations
- Core.Continuation.Cont R A = ((A → R) → R)
Instances For
Monadic unit: wrap a value for any continuation.
pure a = λκ. κ(a)
Equations
- Core.Continuation.Cont.pure a κ = κ a
Instances For
def
Core.Continuation.Cont.map
{R : Type u}
{A : Type v}
{B : Type w}
(f : A → B)
(m : Cont R A)
:
Cont R B
Functorial map: apply a function under the continuation.
map f m = λκ. m(λa. κ(f(a)))
Equations
- Core.Continuation.Cont.map f m κ = m fun (a : A) => κ (f a)
Instances For
@[reducible, inline]
Tower type abbreviation: (A → B) → C.
In Barker & Shan's notation, this is the flat reading of
C | B
─────
A
Equations
- Core.Continuation.Tower C B A = ((A → B) → C)