Basic control operations #
Extends the theory on functors, applicatives and monads.
@[simp]
theorem
pure_id'_seq
{α : Type u}
{F : Type u → Type v}
[Applicative F]
[LawfulApplicative F]
(x : F α)
:
(pure fun (x : α) => x) <*> x = x
def
List.mapAccumRM
{α : Type u}
{β' γ' : Type v}
{m' : Type v → Type w}
[Monad m']
(f : α → β' → m' (β' × γ'))
:
β' → List α → m' (β' × List γ')
Takes a value β and List α and accumulates pairs according to a monadic function f.
Accumulation occurs from the right (i.e., starting from the tail of the list).
Instances For
def
List.mapAccumLM
{α : Type u}
{β' γ' : Type v}
{m' : Type v → Type w}
[Monad m']
(f : β' → α → m' (β' × γ'))
:
β' → List α → m' (β' × List γ')
Takes a value β and List α and accumulates pairs according to a monadic function f.
Accumulation occurs from the left (i.e., starting from the head of the list).
Instances For
theorem
joinM_map_map
{m : Type u → Type u}
[Monad m]
[LawfulMonad m]
{α β : Type u}
(f : α → β)
(a : m (m α))
:
joinM (Functor.map f <$> a) = f <$> joinM a
@[simp]
@[simp]
theorem
joinM_pure
{m : Type u → Type u}
[Monad m]
[LawfulMonad m]
{α : Type u}
(a : m α)
:
joinM (pure a) = a
@[simp]
@[simp]
theorem
guard_false
{F : Type → Type v}
[Alternative F]
{h : Decidable False}
:
guard False = failure
A CommApplicative functor m is a (lawful) applicative functor which behaves identically on
α × β and β × α, so computations can occur in either order.
- commutative_prod {α β : Type u} (a : m α) (b : m β) : Prod.mk <$> a <*> b = (fun (b : β) (a : α) => (a, b)) <$> b <*> a
Computations performed first on
a : αand then onb : βare equal to those performed in the reverse order.
Instances
theorem
CommApplicative.commutative_map
{m : Type u → Type v}
[h : Applicative m]
[CommApplicative m]
{α β γ : Type u}
(a : m α)
(b : m β)
{f : α → β → γ}
: