Documentation

CslibFrontier.Foundations.Control.Monad.StateT

StateT programs applied to a state #

A StateT σ m α program is a function σ → m (α × σ), and handlers are often written and reasoned about as applications x s rather than through StateT.run. Lean's StateT.run_bind, StateT.run_map and StateT.run_pure are stated with .run, so rw cannot use them on such applications. This file restates them for the applied form.

Rewrite interface #

theorem Cslib.StateT.bind_apply {m : Type u → Type v} {σ α β : Type u} [Monad m] (x : StateT σ m α) (f : α → StateT σ m β) (s : σ) :
(x >>= f) s = do let p ← x s f p.1 p.2

StateT.run_bind for a program applied directly to its initial state.

theorem Cslib.StateT.map_apply {m : Type u → Type v} {σ α β : Type u} [Monad m] [LawfulMonad m] (f : α → β) (x : StateT σ m α) (s : σ) :
(f <$> x) s = (fun (p : α × σ) => (f p.1, p.2)) <$> x s

StateT.run_map for a program applied directly to its initial state.

theorem Cslib.StateT.pure_apply {m : Type u → Type v} {σ α : Type u} [Monad m] (a : α) (s : σ) :
pure a s = pure (a, s)

StateT.run_pure for a program applied directly to its initial state.