Continuation Monad #
Monad encapsulating continuation passing programming style, similar to
Haskell's Cont, ContT and MonadCont:
https://hackage.haskell.org/package/mtl-2.2.2/docs/Control-Monad-Cont.html
https://hackage.haskell.org/package/transformers-0.6.2.0/docs/Control-Monad-Trans-Cont.html
- seq_assoc {α β γ : Type u} (x : m α) (g : m (α → β)) (h : m (β → γ)) : h <*> (g <*> x) = Function.comp <$> h <*> g <*> x
- callCC_bind_right {α ω γ : Type u} (cmd : m α) (next : MonadCont.Label ω m γ → α → m ω) : (MonadCont.callCC fun (f : MonadCont.Label ω m γ) => cmd >>= next f) = do let x ← cmd MonadCont.callCC fun (f : MonadCont.Label ω m γ) => next f x
- callCC_bind_left {α : Type u} (β : Type u) (x : α) (dead : MonadCont.Label α m β → β → m α) : (MonadCont.callCC fun (f : MonadCont.Label α m β) => MonadCont.goto f x >>= dead f) = pure x
- callCC_dummy {α β : Type u} (dummy : m α) : (MonadCont.callCC fun (x : MonadCont.Label α m β) => dummy) = dummy
Instances
@[instance_reducible]
instance ContT.instMonadExceptOf {r : Type u} {m : Type u → Type v} (ε : Type u_1) [MonadExceptOf ε m] :
MonadExceptOf ε (ContT r m)
Note that tryCatch does not have correct behavior in this monad:
def foo : ContT Bool (Except String) Bool := do
let x ← try
pure true
catch _ =>
return false
throw s!"oh no {x}"
#eval foo.run pure
-- `Except.ok false`, no error
Here, the throwError is being run inside the try.
See Zulip
for further discussion.
def ExceptT.mkLabel {m : Type u → Type v} [Monad m] {α β ε : Type u} :
MonadCont.Label (Except ε α) m β → MonadCont.Label α (ExceptT ε m) β
Instances For
theorem ExceptT.goto_mkLabel {m : Type u → Type v} [Monad m] {α β ε : Type u} (x : MonadCont.Label (Except ε α) m β) (i : α) :
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} :
MonadCont.Label (Option α) m β → MonadCont.Label α (OptionT m) β
Instances For
theorem OptionT.goto_mkLabel {m : Type u → Type v} [Monad m] {α β : Type u} (x : MonadCont.Label (Option α) m β) (i : α) :
@[simp]
theorem run_callCC {m : Type u → Type v} [Monad m] [MonadCont m] {α β : Type u} (f : MonadCont.Label α (OptionT m) β → OptionT m α) :
(OptionT.callCC f).run = MonadCont.callCC fun (x : MonadCont.Label (Option α) m β) => (f (OptionT.mkLabel x)).run
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 ω] :
MonadCont.Label (α × ω) m β → MonadCont.Label α (WriterT ω m) β
Instances For
def WriterT.mkLabel' {m : Type u → Type v} [Monad m] {α : Type u_1} {β ω : Type u} [Monoid ω] :
MonadCont.Label (α × ω) m β → MonadCont.Label α (WriterT ω m) β
Instances For
theorem WriterT.goto_mkLabel {m : Type u → Type v} [Monad m] {α : Type u_1} {β ω : Type u} [EmptyCollection ω] (x : MonadCont.Label (α × ω) m β) (i : α) :
theorem WriterT.goto_mkLabel' {m : Type u → Type v} [Monad m] {α : Type u_1} {β ω : Type u} [Monoid ω] (x : MonadCont.Label (α × ω) m β) (i : α) :
def WriterT.callCC {m : Type u → Type v} [Monad m] [MonadCont m] {α β ω : Type u} [EmptyCollection ω] (f : MonadCont.Label α (WriterT ω m) β → WriterT ω m α) :
WriterT ω m α
Instances For
@[instance_reducible]
instance instMonadContWriterTOfMonadOfEmptyCollection {m : Type u → Type v} (ω : Type u) [Monad m] [EmptyCollection ω] [MonadCont m] :
def StateT.mkLabel {m : Type u → Type v} {α β σ : Type u} :
MonadCont.Label (α × σ) m (β × σ) → MonadCont.Label α (StateT σ m) β
Instances For
theorem StateT.goto_mkLabel {m : Type u → Type v} {α β σ : Type u} (x : MonadCont.Label (α × σ) m (β × σ)) (i : α) :
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) :
MonadCont.Label α m β → MonadCont.Label α (ReaderT ρ m) β
Instances For
theorem ReaderT.goto_mkLabel {m : Type u → Type v} {α : Type u_1} {ρ β : Type u} (x : MonadCont.Label α m β) (i : α) :
instance instLawfulMonadContReaderT {m : Type u → Type v} {ρ : Type u} [Monad m] [MonadCont m] [LawfulMonadCont m] :
LawfulMonadCont (ReaderT ρ m)