Documentation

Mathlib.Control.Monad.Cont

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

structure MonadCont.Label (α : Type w) (m : Type u → Type v) (β : Type u) :
Type (max v w)
  • apply : αm β
def MonadCont.goto {α : Type u_1} {β : Type u} {m : Type u → Type v} (f : Label α m β) (x : α) :
m β
Equations
class MonadCont (m : Type u → Type v) :
Type (max (u + 1) v)
  • callCC {α β : Type u} : (Label α m βm α)m α
Instances
    class LawfulMonadCont (m : Type u → Type v) [Monad m] [MonadCont m] extends LawfulMonad m :
    Instances
      def ContT (r : Type u) (m : Type u → Type v) (α : Type w) :
      Type (max v w)
      Equations
      • ContT r m α = ((αm r)m r)
      @[reducible, inline]
      abbrev Cont (r : Type u) (α : Type w) :
      Type (max u w)
      Equations
      def ContT.run {r : Type u} {m : Type u → Type v} {α : Type w} :
      ContT r m α(αm r)m r
      Equations
      def ContT.map {r : Type u} {m : Type u → Type v} {α : Type w} (f : m rm r) (x : ContT r m α) :
      ContT r m α
      Equations
      theorem ContT.run_contT_map_contT {r : Type u} {m : Type u → Type v} {α : Type w} (f : m rm r) (x : ContT r m α) :
      (map f x).run = f x.run
      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
      theorem ContT.run_withContT {r : Type u} {m : Type u → Type v} {α β : Type w} (f : (βm r)αm r) (x : ContT r m α) :
      (withContT f x).run = x.run f
      theorem ContT.ext {r : Type u} {m : Type u → Type v} {α : Type w} {x y : ContT r m α} (h : ∀ (f : αm r), x.run f = y.run f) :
      x = y
      theorem ContT.ext_iff {r : Type u} {m : Type u → Type v} {α : Type w} {x y : ContT r m α} :
      x = y ∀ (f : αm r), x.run f = y.run f
      instance ContT.instMonad {r : Type u} {m : Type u → Type v} :
      Monad (ContT r m)
      Equations
      • One or more equations did not get rendered due to their size.
      instance ContT.instLawfulMonad {r : Type u} {m : Type u → Type v} :
      def ContT.monadLift {r : Type u} {m : Type u → Type v} [Monad m] {α : Type u} :
      m αContT r m α
      Equations
      instance ContT.instMonadLiftOfMonad {r : Type u} {m : Type u → Type v} [Monad m] :
      Equations
      theorem ContT.monadLift_bind {r : Type u} {m : Type u → Type v} [Monad m] [LawfulMonad m] {α β : Type u} (x : m α) (f : αm β) :
      instance ContT.instMonadCont {r : Type u} {m : Type u → Type v} :
      Equations
      instance ContT.instLawfulMonadCont {r : Type u} {m : Type u → Type v} :
      instance ContT.instMonadExcept {r : Type u} {m : Type u → Type v} (ε : Type u_1) [MonadExcept ε 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} :
      MonadCont.Label (Except ε α) m βMonadCont.Label α (ExceptT ε m) β
      Equations
      theorem ExceptT.goto_mkLabel {m : Type u → Type v} [Monad m] {α β ε : Type u} (x : MonadCont.Label (Except ε α) m β) (i : α) :
      def ExceptT.callCC {m : Type u → Type v} [Monad m] {ε : Type u} [MonadCont m] {α β : Type u} (f : MonadCont.Label α (ExceptT ε m) βExceptT ε m α) :
      ExceptT ε m α
      Equations
      instance instMonadContExceptT {m : Type u → Type v} [Monad m] {ε : Type u} [MonadCont m] :
      Equations
      def OptionT.mkLabel {m : Type u → Type v} [Monad m] {α β : Type u} :
      Equations
      theorem OptionT.goto_mkLabel {m : Type u → Type v} [Monad m] {α β : Type u} (x : MonadCont.Label (Option α) m β) (i : α) :
      def OptionT.callCC {m : Type u → Type v} [Monad m] [MonadCont m] {α β : Type u} (f : MonadCont.Label α (OptionT m) βOptionT m α) :
      OptionT m α
      Equations
      @[simp]
      theorem run_callCC {m : Type u → Type v} [Monad m] [MonadCont m] {α β : Type u} (f : MonadCont.Label α (OptionT m) βOptionT m α) :
      instance instMonadContOptionT {m : Type u → Type v} [Monad m] [MonadCont m] :
      Equations
      def WriterT.mkLabel {m : Type u → Type v} [Monad m] {α : Type u_1} {β ω : Type u} [EmptyCollection ω] :
      MonadCont.Label (α × ω) m βMonadCont.Label α (WriterT ω m) β
      Equations
      def WriterT.mkLabel' {m : Type u → Type v} [Monad m] {α : Type u_1} {β ω : Type u} [Monoid ω] :
      MonadCont.Label (α × ω) m βMonadCont.Label α (WriterT ω m) β
      Equations
      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 α
      Equations
      def WriterT.callCC' {m : Type u → Type v} [Monad m] [MonadCont m] {α β ω : Type u} [Monoid ω] (f : MonadCont.Label α (WriterT ω m) βWriterT ω m α) :
      WriterT ω m α
      Equations
      instance instMonadContWriterTOfMonadOfMonoid {m : Type u → Type v} (ω : Type u) [Monad m] [Monoid ω] [MonadCont m] :
      Equations
      def StateT.mkLabel {m : Type u → Type v} {α β σ : Type u} :
      MonadCont.Label (α × σ) m (β × σ)MonadCont.Label α (StateT σ m) β
      Equations
      theorem StateT.goto_mkLabel {m : Type u → Type v} {α β σ : Type u} (x : MonadCont.Label (α × σ) m (β × σ)) (i : α) :
      MonadCont.goto (mkLabel x) i = StateT.mk fun (s : σ) => MonadCont.goto x (i, s)
      def StateT.callCC {m : Type u → Type v} {σ : Type u} [MonadCont m] {α β : Type u} (f : MonadCont.Label α (StateT σ m) βStateT σ m α) :
      StateT σ m α
      Equations
      instance instMonadContStateT {m : Type u → Type v} {σ : Type u} [MonadCont m] :
      Equations
      def ReaderT.mkLabel {m : Type u → Type v} {α : Type u_1} {β : Type u} (ρ : Type u) :
      MonadCont.Label α m βMonadCont.Label α (ReaderT ρ m) β
      Equations
      theorem ReaderT.goto_mkLabel {m : Type u → Type v} {α : Type u_1} {ρ β : Type u} (x : MonadCont.Label α m β) (i : α) :
      def ReaderT.callCC {m : Type u → Type v} {ε : Type u} [MonadCont m] {α β : Type u} (f : MonadCont.Label α (ReaderT ε m) βReaderT ε m α) :
      ReaderT ε m α
      Equations
      instance instMonadContReaderT {m : Type u → Type v} {ρ : Type u} [MonadCont m] :
      Equations
      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 : α₁ α₂) :
      ContT r₁ m₁ α₁ ContT r₂ m₂ α₂

      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.