Continuation Monad #
General-purpose continuation monad, following [BS14].
The type Cont R A := (A → R) → R underlies lifted question types
(Lifted.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
- Semantics.Composition.Continuation.Cont R A = ((A → R) → R)
Instances For
Functorial map: apply a function under the continuation.
map f m = λκ. m(λa. κ(f(a)))
Equations
- Semantics.Composition.Continuation.Cont.map f m κ = m fun (a : A) => κ (f a)
Instances For
Tower type abbreviation: (A → B) → C.
In Barker & Shan's notation, this is the flat reading of
C | B
─────
A
Equations
- Semantics.Composition.Continuation.Tower C B A = ((A → B) → C)
Instances For
The continuation monad's laws (left/right identity, associativity, and the
functor laws) are exactly those of LawfulMonad, so we register Cont R as a
lawful monad rather than restating them as standalone rfl theorems. R is
fixed to Type (not universe-polymorphic) for Lean's Monad class.
Equations
- Semantics.Composition.Continuation.instFunctorCont = { map := fun {α β : Type ?u.1} => Semantics.Composition.Continuation.Cont.map }
Equations
- Semantics.Composition.Continuation.instPureCont = { pure := fun {α : Type ?u.1} => Semantics.Composition.Continuation.Cont.pure }
Equations
- Semantics.Composition.Continuation.instBindCont = { bind := fun {α β : Type ?u.1} => Semantics.Composition.Continuation.Cont.bind }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Lower of pure is identity. (Not a monad law — a fact about Cont.lower.)
Scope as bind order #
Scope ambiguity in the continuation framework is the order of monadic
bind — surface scope binds the subject first, inverse scope the object
first — and lower is generalized-quantifier application
([BS14]). These hold for any quantifier and predicate.
Nested Cont binds compute nested GQ application; the bind nesting
determines scope order.
Scope ambiguity = bind order: the two readings of Q₁ R Q₂ are
Q₁ nested outside Q₂ vs Q₂ outside Q₁, each reducing to GQ
application in the corresponding order.
The bind-order pattern extends to arbitrary depth.