Documentation

Projects.Util.Monad

def sequence' {α : Type} {M : Type → Type} [hM : Monad M] (ms : List (M α)) :
Equations
Instances For
    def replicateM {α : Type} {M : Type → Type} [hM : Monad M] (n : ℕ) (m : M α) :
    M (List α)
    Equations
    Instances For
      def replicateM' {α : Type} {M : Type → Type} [hM : Monad M] (n : ℕ) (m : M α) :
      Equations
      Instances For
        class MonadCnd {M : Type → Type} [hM : Monad M] (p : {α : Type} → M α → Prop) :
        • pure {α : Type} {x : α} : p (Pure.pure x)
        • bind {α β : Type} {m : M α} {f : α → M β} : p m → (∀ (x : α), p (f x)) → p (m >>= f)
        Instances
          def void' {M : Type u → Type v} {α : Type u} [hm : Monad M] (m : M α) :
          Equations
          Instances For
            def void {M : Type → Type} {α : Type} [hm : Monad M] (m : M α) :
            Equations
            Instances For
              @[simp]
              theorem Id_pure {α : Type} :
              pure = fun (a : α) => a
              @[simp]
              theorem Id_bind {α β : Type} {m : Id α} {f : α → Id β} :
              m >>= f = f m
              @[inline]
              def gets {α : Type} {M : Type → Type} [hM : Monad M] {σ : Type} [hσ : MonadState σ M] (f : σ → α) :
              M α
              Equations
              Instances For
                theorem run_run_snd {α β σ : Type} {m₁ : StateM σ α} {m₂ : StateM σ β} {x : σ} :
                StateT.run m₂ (StateT.run m₁ x).2 = StateT.run (do (fun (x : α) => ()) <$> m₁ m₂) x
                @[simp]
                theorem run_gets {α : Type} {M : Type → Type} [hM : Monad M] {σ : Type} {f : σ → α} :
                (gets f).run = (do let x ← get pure (f x)).run
                @[simp]
                theorem run_set {M : Type → Type} [hM : Monad M] {σ : Type} {s : σ} :
                (set s).run = fun (x : σ) => pure ((), s)
                @[simp]
                theorem run_set' {M : Type → Type} [hM : Monad M] {σ : Type} {s : σ} :
                (StateT.set s).run = fun (x : σ) => pure ((), s)
                @[simp]
                theorem sequence_nil {α : Type} {M : Type → Type} [hM : Monad M] :
                @[simp]
                theorem sequence_cons {α : Type} {M : Type → Type} [hM : Monad M] [hM₂ : LawfulMonad M] {m : M α} {ms : List (M α)} :
                sequence (m :: ms) = do let x ← m let xs ← sequence ms pure (x :: xs)
                @[simp]
                theorem sequence'_nil {α : Type} {M : Type → Type} [hM : Monad M] [hM₂ : LawfulMonad M] :
                @[simp]
                theorem sequence'_cons {α : Type} {M : Type → Type} [hM : Monad M] [hM₂ : LawfulMonad M] {m : M α} {ms : List (M α)} :
                sequence' (m :: ms) = do let _ ← m sequence' ms
                theorem MonadCnd.map {α β : Type} {M : Type → Type} [hM : Monad M] [hM₂ : LawfulMonad M] {p : {α : Type} → M α → Prop} [H : MonadCnd p] {f : α → β} {m : M α} (h₁ : p m) :
                p (f <$> m)
                theorem MonadCnd.sequence {α : Type} {M : Type → Type} [hM : Monad M] [hM₂ : LawfulMonad M] {p : {α : Type} → M α → Prop} [H : MonadCnd p] {ms : List (M α)} (h₁ : ∀ m ∈ ms, p m) :
                theorem MonadCnd.sequence' {α : Type} {M : Type → Type} [hM : Monad M] [hM₂ : LawfulMonad M] {p : {α : Type} → M α → Prop} [H : MonadCnd p] {ms : List (M α)} (h₁ : ∀ m ∈ ms, p m) :
                theorem MonadCnd.replicateM {α : Type} {M : Type → Type} [hM : Monad M] [hM₂ : LawfulMonad M] {p : {α : Type} → M α → Prop} [H : MonadCnd p] {m : M α} {n : ℕ} (h₁ : p m) :
                theorem MonadCnd.replicateM' {α : Type} {M : Type → Type} [hM : Monad M] [hM₂ : LawfulMonad M] {p : {α : Type} → M α → Prop} [H : MonadCnd p] {m : M α} {n : ℕ} (h₁ : p m) :
                theorem List.mapM_eq_sequence {α β : Type} {M : Type → Type} [hM : Monad M] [hM₂ : LawfulMonad M] {xs : List α} {f : α → M β} :
                mapM f xs = sequence (map f xs)
                theorem List.forM_eq_sequence' {α : Type} {M : Type → Type} [hM : Monad M] [hM₂ : LawfulMonad M] {xs : List α} {f : α → M Unit} :
                xs.forM f = sequence' (map f xs)
                @[simp]
                theorem fst_run_void {α σ : Type} {m : StateM σ α} {s : σ} :
                (StateT.run (void m) s).1 = ()
                @[simp]
                theorem snd_run_void {α σ : Type} {m : StateM σ α} {s : σ} :
                (StateT.run (void m) s).2 = (StateT.run m s).2
                theorem run_run_eq_bind {α β σ : Type} {s : σ} {m₁ : StateM σ α} {m₂ : StateM σ β} :
                StateT.run m₂ (StateT.run m₁ s).2 = StateT.run (do void m₁ m₂) s
                @[simp]
                theorem run_pure {α σ : Type} {s : σ} {x : α} :
                (pure x s).run = (x, s)
                @[simp]
                theorem run_bind {α β σ : Type} {m : StateM σ α} {s : σ} {f : α → StateM σ β} :
                ((m >>= f) s).run = StateT.run (f (StateT.run m s).1) (StateT.run m s).2