The combined state and list monad transformer.
StateListT σ α
is equivalent to StateT σ (ListT α)
but more efficient.
WARNING: StateListT σ α m
is only a monad if m
is a commutative monad.
For example,
def problem : StateListT Unit (StateM (Array Nat)) Unit := do
Alternative.orElse (pure ()) (fun _ => pure ())
StateListT.lift $ modify (·.push 0)
StateListT.lift $ modify (·.push 1)
#eval ((problem.run' ()).run #[]).2
will yield either #[0,1,0,1]
, or #[0,0,1,1]
, depending on the order in which the actions
in the do block are combined.
StateList
StateList
is a List with a state associated to each element.
This is used instead of List (α × σ)
as it is more efficient.
- nil
{σ α : Type u}
: Mathlib.Meta.FunProp.StateList σ α
.nil is the empty list.
- cons {σ α : Type u} : α → σ → Mathlib.Meta.FunProp.StateList σ α → Mathlib.Meta.FunProp.StateList σ α
Instances For
Equations
- Mathlib.Meta.FunProp.StateList.instAppend = { append := Mathlib.Meta.FunProp.StateList.append✝ }
The combined state and list monad transformer.
Equations
- Mathlib.Meta.FunProp.StateListT σ m α = (σ → m (Mathlib.Meta.FunProp.StateList σ α))
Instances For
Run x
on a given state s
, returning the list of values with corresponding states.
Instances For
Run x
on a given state s
, returning the list of values.
Instances For
The combined state and list monad.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Return the state from StateListT σ m
.
Equations
- Mathlib.Meta.FunProp.StateListT.get s = pure (Mathlib.Meta.FunProp.StateList.cons s s Mathlib.Meta.FunProp.StateList.nil)
Instances For
Set the state in StateListT σ m
.
Equations
- Mathlib.Meta.FunProp.StateListT.set s' x✝ = pure (Mathlib.Meta.FunProp.StateList.cons PUnit.unit s' Mathlib.Meta.FunProp.StateList.nil)
Instances For
Modify and get the state in StateListT σ m
.
Equations
- Mathlib.Meta.FunProp.StateListT.modifyGet f s = pure (Mathlib.Meta.FunProp.StateList.cons (f s).fst (f s).snd Mathlib.Meta.FunProp.StateList.nil)
Instances For
Lift an action from m α
to StateListT σ m α
.
Equations
- Mathlib.Meta.FunProp.StateListT.lift t s = do let a ← t pure (Mathlib.Meta.FunProp.StateList.cons a s Mathlib.Meta.FunProp.StateList.nil)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.