mathlib documentation

control.​monad.​writer

control.​monad.​writer

structure writer_t  :
Type u(Type uType v)Type uType (max u v)
  • run : m × ω)

def writer  :
Type uType uType u

Equations
@[ext]
theorem writer_t.​ext {ω : Type u} {m : Type uType v} [monad m] {α : Type u} (x x' : writer_t ω m α) :
x.run = x'.runx = x'

def writer_t.​tell {ω : Type u} {m : Type uType v} [monad m] :
ω → writer_t ω m punit

Equations
def writer_t.​listen {ω : Type u} {m : Type uType v} [monad m] {α : Type u} :
writer_t ω m αwriter_t ω m × ω)

Equations
def writer_t.​pass {ω : Type u} {m : Type uType v} [monad m] {α : Type u} :
writer_t ω m × (ω → ω))writer_t ω m α

Equations
def writer_t.​pure {ω : Type u} {m : Type uType v} [monad m] {α : Type u} [has_one ω] :
α → writer_t ω m α

Equations
def writer_t.​bind {ω : Type u} {m : Type uType v} [monad m] {α β : Type u} [has_mul ω] :
writer_t ω m α(α → writer_t ω m β)writer_t ω m β

Equations
@[instance]
def writer_t.​monad {ω : Type u} {m : Type uType v} [monad m] [has_one ω] [has_mul ω] :

Equations
@[instance]
def writer_t.​is_lawful_monad {ω : Type u} {m : Type uType v} [monad m] [monoid ω] [is_lawful_monad m] :

Equations
def writer_t.​lift {ω : Type u} {m : Type uType v} [monad m] {α : Type u} [has_one ω] :
m αwriter_t ω m α

Equations
@[instance]
def writer_t.​has_monad_lift {ω : Type u} (m : Type uType u_1) [monad m] [has_one ω] :

Equations
def writer_t.​monad_map {ω : Type u} {m : Type uType u_1} {m' : Type uType u_2} [monad m] [monad m'] {α : Type u} :
(Π {α : Type u}, m αm' α)writer_t ω m αwriter_t ω m' α

Equations
@[instance]
def writer_t.​monad_functor {ω : Type u} (m m' : Type uType u_1) [monad m] [monad m'] :
monad_functor m m' (writer_t ω m) (writer_t ω m')

Equations
def writer_t.​adapt {ω : Type u} {m : Type uType v} [monad m] {ω' α : Type u} :
(ω → ω')writer_t ω m αwriter_t ω' m α

Equations
@[instance]
def writer_t.​monad_except {ω : Type u} {m : Type uType v} [monad m] (ε : out_param (Type u_1)) [has_one ω] [monad m] [monad_except ε m] :

Equations
@[class]
structure monad_writer  :
out_param (Type u)(Type uType v)Type (max (u+1) v)
  • tell : ω → m punit
  • listen : Π {α : Type ?}, m αm × ω)
  • pass : Π {α : Type ?}, m × (ω → ω))m α

An implementation of MonadReader. It does not contain local because this function cannot be lifted using monad_lift. Instead, the monad_reader_adapter class provides the more general adapt_reader function.

Note: This class can be seen as a simplification of the more "principled" definition lean class monad_reader (ρ : out_param (Type u)) (n : Type u → Type u) := (lift {α : Type u} : (∀ {m : Type u → Type u} [monad m], reader_t ρ m α) → n α)

Instances
@[instance]
def writer_t.​monad_writer {ω : Type u} {m : Type uType v} [monad m] :

Equations
@[instance]
def reader_t.​monad_writer {ω ρ : Type u} {m : Type uType v} [monad m] [monad_writer ω m] :

Equations
def swap_right {α : Type u_1} {β : Type u_2} {γ : Type u_3} :
× β) × γ× γ) × β

Equations
@[instance]
def state_t.​monad_writer {ω σ : Type u} {m : Type uType v} [monad m] [monad_writer ω m] :

Equations
def except_t.​pass_aux {ε : Type u_1} {α : Type u_2} {ω : Type u_3} :
except ε × (ω → ω))except ε α × (ω → ω)

Equations
@[instance]
def except_t.​monad_writer {ω ε : Type u} {m : Type uType v} [monad m] [monad_writer ω m] :

Equations
def option_t.​pass_aux {α : Type u_1} {ω : Type u_2} :
option × (ω → ω))option α × (ω → ω)

Equations
@[instance]
def option_t.​monad_writer {ω : Type u} {m : Type uType v} [monad m] [monad_writer ω m] :

Equations
@[class]
structure monad_writer_adapter  :
out_param (Type u)out_param (Type u)(Type uType v)(Type uType v)Type (max (u+1) v)
  • adapt_writer : Π {α : Type ?}, (ω → ω')m αm' α

Adapt a monad stack, changing the type of its top-most environment.

This class is comparable to Control.Lens.Magnify, but does not use lenses (why would it), and is derived automatically for any transformer implementing monad_functor.

Note: This class can be seen as a simplification of the more "principled" definition

class monad_reader_functor (ρ ρ' : out_param (Type u)) (n n' : Type u  Type u) :=
(map {α : Type u} : ( {m : Type u  Type u} [monad m], reader_t ρ m α  reader_t ρ' m α)  n α  n' α)
Instances
@[nolint, instance]
def monad_writer_adapter_trans {ω ω' : Type u} {m m' n n' : Type uType v} [monad_writer_adapter ω ω' m m'] [monad_functor m m' n n'] :

Transitivity.

This instance generates the type-class problem with a metavariable argument (which is why this is marked as [nolint dangerous_instance]). Currently that is not a problem, as there are almost no instances of monad_functor or monad_writer_adapter.

see Note [lower instance priority]

Equations
@[instance]
def writer_t.​monad_writer_adapter {ω ω' : Type u} {m : Type uType v} [monad m] :
monad_writer_adapter ω ω' (writer_t ω m) (writer_t ω' m)

Equations
@[instance]
def writer_t.​monad_run (ω : Type u) (m : Type uType (max u u_1)) (out : out_param (Type uType (max u u_1))) [monad_run out m] :
monad_run (λ (α : Type u), out × ω)) (writer_t ω m)

Equations
def writer_t.​equiv {m₁ : Type u₀Type v₀} {m₂ : Type u₁Type v₁} {α₁ ω₁ : Type u₀} {α₂ ω₂ : Type u₁} :
m₁ (α₁ × ω₁) m₂ (α₂ × ω₂)writer_t ω₁ m₁ α₁ writer_t ω₂ m₂ α₂

reduce the equivalence between two writer monads to the equivalence between their underlying monad

Equations