Documentation

ToCslib.Data.Fin.MOfFn

Monadic sequencing of Fin-indexed families #

Fin.mOfFn n f runs f 0, …, f (n - 1) in order and collects the results as a function Fin n → α. It is the function-valued counterpart of Mathlib's List.Vector.mOfFn; the pinned core, Batteries and Mathlib define no monadic Fin.ofFn. The body is exposed so that its two equations, Fin.mOfFn_zero and Fin.mOfFn_succ, hold by rfl for every importer.

The collected function is a chain of Fin.cons. This module imports the compiler simplifications of ToCslib.Data.Fin.Cases, so compiled code reads entry i of the chain in time linear in i.

def Fin.mOfFn {m : Type u → Type v} [Monad m] {α : Type u} (n : ℕ) :
(Fin n → m α) → m (Fin n → α)

Run a Fin n-indexed family of monadic computations in index order and collect the results as a function on Fin n.

Equations
Instances For
    @[simp]
    theorem Fin.mOfFn_zero {m : Type u → Type v} [Monad m] {α : Type u} (f : Fin 0 → m α) :
    theorem Fin.mOfFn_succ {m : Type u → Type v} [Monad m] {α : Type u} (n : ℕ) (f : Fin (n + 1) → m α) :
    mOfFn (n + 1) f = do let a ← f 0 let rest ← mOfFn n fun (i : Fin n) => f i.succ pure (cons a rest)
    @[simp]
    theorem Fin.mOfFn_pure {m : Type u → Type v} [Monad m] {α : Type u} [LawfulMonad m] (n : ℕ) (f : Fin n → α) :
    (mOfFn n fun (i : Fin n) => pure (f i)) = pure f

    Sequencing a family of pure computations returns the family of their values.