Documentation

ToMathlib.Control.Monad.Commutative

Commutative monads #

def Monad.CommutativeAt (m : Type u → Type v) [Monad m] {α β : Type u} (ma : m α) (mb : m β) :

Two monadic actions ma : m α and mb : m β are commutative if the following holds:

(do let a ← ma; let b ← mb; pure (a, b)) = (do let b ← mb; let a ← ma; pure (a, b))
Equations
    Instances For
      class Monad.Commutative (m : Type u → Type v) [Monad m] :

      A monad is commutative if any two monadic actions ma : m α and mb : m β can be applied in any order. In other words, the following holds:

      (do let a ← ma; let b ← mb; pure (a, b)) = (do let b ← mb; let a ← ma; pure (a, b))
      
      Instances
        @[simp]
        theorem Monad.bind_comm_comp {m : Type u_1 → Type u_2} [Monad m] [LawfulMonad m] [Commutative m] {α β γ : Type u_1} (ma : m α) (mb : m β) (f : α × βm γ) :
        (do let ama let bmb f (a, b)) = do let bmb let ama f (a, b)
        theorem Monad.bind_swap {m : Type u_1 → Type u_2} [Monad m] [LawfulMonad m] [Commutative m] {α β γ : Type u_1} (ma : m α) (mb : m β) (f : α × βm γ) :
        (do let ama let bmb f (a, b)) = do let bmb let ama f (a, b)

        Alias of Monad.bind_comm_comp.

        @[simp]
        theorem Monad.CommutativeAt.bind_comm {m : Type (max u_1 u_2) → Type u_3} [Monad m] [LawfulMonad m] {α β : Type (max u_1 u_2)} (ma : m α) (mb : m β) (h : CommutativeAt m ma mb) :
        (do let ama let bmb pure (a, b)) = do let bmb let ama pure (a, b)
        @[simp]
        theorem Monad.CommutativeAt.bind_comm_comp {m : Type u_1 → Type u_2} [Monad m] [LawfulMonad m] {α β γ : Type u_1} (ma : m α) (mb : m β) (h : CommutativeAt m ma mb) (f : α × βm γ) :
        (do let ama let bmb f (a, b)) = do let bmb let ama f (a, b)

        TODO: fix below lemmas & figure out a good naming scheme #

        theorem Monad.bind_comm_triple_swap_12 {m : Type u_1 → Type u_2} [Monad m] [LawfulMonad m] [Commutative m] {α β γ δ : Type u_1} (ma : m α) (mb : m β) (mc : m γ) (f : α × β × γm δ) :
        (do let ama let bmb let cmc f (a, b, c)) = do let bmb let ama let cmc f (a, b, c)

        Commutativity extends to sequences of three operations (swap first two)

        theorem Monad.bind_comm_triple_swap_23 {m : Type u_1 → Type u_2} [Monad m] [LawfulMonad m] [Commutative m] {α β γ δ : Type u_1} (ma : m α) (mb : m β) (mc : m γ) (f : α × β × γm δ) :
        (do let ama let bmb let cmc f (a, b, c)) = do let ama let cmc let bmb f (a, b, c)

        Swap second and third elements in a triple of monadic actions

        theorem Monad.bind_comm_quad_swap_12 {m : Type u_1 → Type u_2} [Monad m] [LawfulMonad m] [Commutative m] {α β γ δ ε : Type u_1} (ma : m α) (mb : m β) (mc : m γ) (md : m δ) (f : α × β × γ × δm ε) :
        (do let ama let bmb let cmc let dmd f (a, b, c, d)) = do let bmb let ama let cmc let dmd f (a, b, c, d)
        theorem Monad.bind_comm_quad_swap_23 {m : Type u_1 → Type u_2} [Monad m] [LawfulMonad m] [Commutative m] {α β γ δ ε : Type u_1} (ma : m α) (mb : m β) (mc : m γ) (md : m δ) (f : α × β × γ × δm ε) :
        (do let ama let bmb let cmc let dmd f (a, b, c, d)) = do let ama let cmc let bmb let dmd f (a, b, c, d)
        theorem Monad.bind_comm_quad_swap_34 {m : Type u_1 → Type u_2} [Monad m] [LawfulMonad m] [Commutative m] {α β γ δ ε : Type u_1} (ma : m α) (mb : m β) (mc : m γ) (md : m δ) (f : α × β × γ × δm ε) :
        (do let ama let bmb let cmc let dmd f (a, b, c, d)) = do let ama let bmb let dmd let cmc f (a, b, c, d)

        The identity monad is commutative

        instance Monad.instCommutativeReaderT {ρ : Type u_1} {m : Type u_1 → Type u_2} [Monad m] [Commutative m] :

        The ReaderT ρ m monad is commutative if the underlying monad is commutative

        The set monad is commutative. This is not registered as an instance similar to how Set.monad is not registered as an instance.

        Equations
          Instances For