Continuation Monad #
Monad encapsulating continuation passing programming style, similar to
Haskell's Cont
, ContT
and MonadCont
:
http://hackage.haskell.org/package/mtl-2.2.2/docs/Control-Monad-Cont.html
def
MonadCont.goto
{α : Type u_1}
{β : Type u}
{m : Type u → Type v}
(f : ContT.Label α m β)
(x : α)
:
m β
Equations
- ContT.goto f x = f.apply x
Instances For
- callCC_bind_right {α ω γ : Type u} (cmd : m α) (next : ContT.Label ω m γ → α → m ω) : (MonadCont.callCC fun (f : ContT.Label ω m γ) => cmd >>= next f) = do let x ← cmd MonadCont.callCC fun (f : ContT.Label ω m γ) => next f x
- callCC_bind_left {α : Type u} (β : Type u) (x : α) (dead : ContT.Label α m β → β → m α) : (MonadCont.callCC fun (f : ContT.Label α m β) => ContT.goto f x >>= dead f) = pure x
- callCC_dummy {α β : Type u} (dummy : m α) : (MonadCont.callCC fun (x : ContT.Label α m β) => dummy) = dummy
Instances
def
ContT.withContT
{r : Type u}
{m : Type u → Type v}
{α β : Type w}
(f : (β → m r) → α → m r)
(x : ContT r m α)
:
ContT r m β
Equations
- ContT.withContT f x g = x (f g)
Instances For
theorem
ContT.run_withContT
{r : Type u}
{m : Type u → Type v}
{α β : Type w}
(f : (β → m r) → α → m r)
(x : ContT r m α)
:
(ContT.withContT f x).run = x.run ∘ f
theorem
ContT.monadLift_bind
{r : Type u}
{m : Type u → Type v}
[Monad m]
[LawfulMonad m]
{α β : Type u}
(x : m α)
(f : α → m β)
:
ContT.monadLift (x >>= f) = ContT.monadLift x >>= ContT.monadLift ∘ f
instance
ContT.instMonadExcept
{r : Type u}
{m : Type u → Type v}
(ε : Type u_1)
[MonadExcept ε m]
:
MonadExcept ε (ContT r m)
Equations
- One or more equations did not get rendered due to their size.
def
ExceptT.mkLabel
{m : Type u → Type v}
[Monad m]
{α β ε : Type u}
:
ContT.Label (Except ε α) m β → ContT.Label α (ExceptT ε m) β
Equations
- ExceptT.mkLabel { apply := f } = { apply := fun (a : α) => monadLift (f (Except.ok a)) }
Instances For
theorem
ExceptT.goto_mkLabel
{m : Type u → Type v}
[Monad m]
{α β ε : Type u}
(x : ContT.Label (Except ε α) m β)
(i : α)
:
ContT.goto (ExceptT.mkLabel x) i = ExceptT.mk (Except.ok <$> ContT.goto x (Except.ok i))
def
ExceptT.callCC
{m : Type u → Type v}
[Monad m]
{ε : Type u}
[MonadCont m]
{α β : Type u}
(f : ContT.Label α (ExceptT ε m) β → ExceptT ε m α)
:
ExceptT ε m α
Equations
- ExceptT.callCC f = ExceptT.mk (MonadCont.callCC fun (x : ContT.Label (Except ε α) m β) => (f (ExceptT.mkLabel x)).run)
Instances For
instance
instLawfulMonadContExceptT
{m : Type u → Type v}
[Monad m]
{ε : Type u}
[MonadCont m]
[LawfulMonadCont m]
:
LawfulMonadCont (ExceptT ε m)
def
OptionT.mkLabel
{m : Type u → Type v}
[Monad m]
{α β : Type u}
:
ContT.Label (Option α) m β → ContT.Label α (OptionT m) β
Equations
- OptionT.mkLabel { apply := f } = { apply := fun (a : α) => monadLift (f (some a)) }
Instances For
theorem
OptionT.goto_mkLabel
{m : Type u → Type v}
[Monad m]
{α β : Type u}
(x : ContT.Label (Option α) m β)
(i : α)
:
ContT.goto (OptionT.mkLabel x) i = OptionT.mk do
let a ← ContT.goto x (some i)
pure (some a)
def
OptionT.callCC
{m : Type u → Type v}
[Monad m]
[MonadCont m]
{α β : Type u}
(f : ContT.Label α (OptionT m) β → OptionT m α)
:
OptionT m α
Equations
- OptionT.callCC f = OptionT.mk (MonadCont.callCC fun (x : ContT.Label (Option α) m β) => (f (OptionT.mkLabel x)).run)
Instances For
instance
instLawfulMonadContOptionT
{m : Type u → Type v}
[Monad m]
[MonadCont m]
[LawfulMonadCont m]
:
def
WriterT.mkLabel
{m : Type u → Type v}
[Monad m]
{α : Type u_1}
{β ω : Type u}
[EmptyCollection ω]
:
ContT.Label (α × ω) m β → ContT.Label α (WriterT ω m) β
Equations
- WriterT.mkLabel { apply := f } = { apply := fun (a : α) => monadLift (f (a, ∅)) }
Instances For
def
WriterT.mkLabel'
{m : Type u → Type v}
[Monad m]
{α : Type u_1}
{β ω : Type u}
[Monoid ω]
:
ContT.Label (α × ω) m β → ContT.Label α (WriterT ω m) β
Equations
- WriterT.mkLabel' { apply := f } = { apply := fun (a : α) => monadLift (f (a, 1)) }
Instances For
theorem
WriterT.goto_mkLabel
{m : Type u → Type v}
[Monad m]
{α : Type u_1}
{β ω : Type u}
[EmptyCollection ω]
(x : ContT.Label (α × ω) m β)
(i : α)
:
ContT.goto (WriterT.mkLabel x) i = monadLift (ContT.goto x (i, ∅))
theorem
WriterT.goto_mkLabel'
{m : Type u → Type v}
[Monad m]
{α : Type u_1}
{β ω : Type u}
[Monoid ω]
(x : ContT.Label (α × ω) m β)
(i : α)
:
ContT.goto (WriterT.mkLabel' x) i = monadLift (ContT.goto x (i, 1))
def
WriterT.callCC
{m : Type u → Type v}
[Monad m]
[MonadCont m]
{α β ω : Type u}
[EmptyCollection ω]
(f : ContT.Label α (WriterT ω m) β → WriterT ω m α)
:
WriterT ω m α
Equations
- WriterT.callCC f = WriterT.mk (MonadCont.callCC (WriterT.run ∘ f ∘ WriterT.mkLabel))
Instances For
def
WriterT.callCC'
{m : Type u → Type v}
[Monad m]
[MonadCont m]
{α β ω : Type u}
[Monoid ω]
(f : ContT.Label α (WriterT ω m) β → WriterT ω m α)
:
WriterT ω m α
Equations
- WriterT.callCC' f = WriterT.mk (MonadCont.callCC (WriterT.run ∘ f ∘ WriterT.mkLabel'))
Instances For
instance
instMonadContWriterTOfMonadOfEmptyCollection
{m : Type u → Type v}
(ω : Type u)
[Monad m]
[EmptyCollection ω]
[MonadCont m]
:
Equations
- instMonadContWriterTOfMonadOfEmptyCollection ω = { callCC := fun {α β : Type ?u.35} => WriterT.callCC }
def
StateT.mkLabel
{m : Type u → Type v}
{α β σ : Type u}
:
ContT.Label (α × σ) m (β × σ) → ContT.Label α (StateT σ m) β
Equations
- StateT.mkLabel { apply := f } = { apply := fun (a : α) => StateT.mk fun (s : σ) => f (a, s) }
Instances For
theorem
StateT.goto_mkLabel
{m : Type u → Type v}
{α β σ : Type u}
(x : ContT.Label (α × σ) m (β × σ))
(i : α)
:
ContT.goto (StateT.mkLabel x) i = StateT.mk fun (s : σ) => ContT.goto x (i, s)
def
StateT.callCC
{m : Type u → Type v}
{σ : Type u}
[MonadCont m]
{α β : Type u}
(f : ContT.Label α (StateT σ m) β → StateT σ m α)
:
StateT σ m α
Equations
- StateT.callCC f = StateT.mk fun (r : σ) => MonadCont.callCC fun (f' : ContT.Label (α × σ) m (β × σ)) => (f (StateT.mkLabel f')).run r
Instances For
instance
instLawfulMonadContStateT
{m : Type u → Type v}
{σ : Type u}
[Monad m]
[MonadCont m]
[LawfulMonadCont m]
:
LawfulMonadCont (StateT σ m)
def
ReaderT.mkLabel
{m : Type u → Type v}
{α : Type u_1}
{β : Type u}
(ρ : Type u)
:
ContT.Label α m β → ContT.Label α (ReaderT ρ m) β
Equations
- ReaderT.mkLabel ρ { apply := f } = { apply := monadLift ∘ f }
Instances For
theorem
ReaderT.goto_mkLabel
{m : Type u → Type v}
{α : Type u_1}
{ρ β : Type u}
(x : ContT.Label α m β)
(i : α)
:
ContT.goto (ReaderT.mkLabel ρ x) i = monadLift (ContT.goto x i)
def
ReaderT.callCC
{m : Type u → Type v}
{ε : Type u}
[MonadCont m]
{α β : Type u}
(f : ContT.Label α (ReaderT ε m) β → ReaderT ε m α)
:
ReaderT ε m α
Equations
- ReaderT.callCC f = ReaderT.mk fun (r : ε) => MonadCont.callCC fun (f' : ContT.Label α m β) => (f (ReaderT.mkLabel ε f')).run r
Instances For
instance
instLawfulMonadContReaderT
{m : Type u → Type v}
{ρ : Type u}
[Monad m]
[MonadCont m]
[LawfulMonadCont m]
:
LawfulMonadCont (ReaderT ρ m)
def
ContT.equiv
{m₁ : Type u₀ → Type v₀}
{m₂ : Type u₁ → Type v₁}
{α₁ r₁ : Type u₀}
{α₂ r₂ : Type u₁}
(F : m₁ r₁ ≃ m₂ r₂)
(G : α₁ ≃ α₂)
:
reduce the equivalence between two continuation passing monads to the equivalence between their underlying monad
Equations
- One or more equations did not get rendered due to their size.