Commutative monads #
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
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 γ)
:
Alias of Monad.bind_comm_comp.
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 δ)
:
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 δ)
:
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 ε)
:
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 ε)
:
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 ε)
:
instance
Monad.instCommutativeExceptOfSubsingleton
{ε : Type u_1}
[Subsingleton ε]
:
Commutative (Except ε)
instance
Monad.instCommutativeReaderT
{ρ : Type u_1}
{m : Type u_1 → Type u_2}
[Monad m]
[Commutative m]
:
Commutative (ReaderT ρ 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.