Transport of loops along monad morphisms #
A monad morphism F : ∀ {β}, m β → n β (cslib's IsMonadHom predicate) commutes with every
loop combinator that do-notation elaborates to. cslib's IsMonadHom.map_listMapM,
map_listForM, map_listFoldlM and their relatives cover the list functions; this module adds
the forIn' / forIn loops over lists and, through Std.Internal.PureForIn, over every
container whose loop is the loop over the list ForIn.toList computes (arrays, ranges,
iterators, …).
Lists #
Containers iterating over a list #
Std.Internal.PureForIn identifies the containers (arrays, ranges, iterators, …) whose loop is
the loop over the list ForIn.toList computes; transport then reduces to the list case.
theorem Cslib.IsMonadHom.map_forIn_of_pureForIn {m : Type u → Type v} {n : Type u → Type w} [Monad m] [Monad n] {F : {β : Type u} → m β → n β} (hf : IsMonadHom m n fun {α : Type u} => F) {ρ : Type w₁} {α : Type u₁} {β : Type u} [ForIn m ρ α] [ForIn n ρ α] [ForIn Id ρ α] [Std.Internal.PureForIn m ρ α] [Std.Internal.PureForIn n ρ α] (xs : ρ) (init : β) (f : α → β → m (ForInStep β)) :
theorem Cslib.IsMonadHom.map_forIn'_of_pureForIn' {m : Type u → Type v} {n : Type u → Type w} [Monad m] [Monad n] {F : {β : Type u} → m β → n β} (hf : IsMonadHom m n fun {α : Type u} => F) {ρ : Type w₁} {α : Type u₁} {β : Type u} {d : Membership α ρ} [ForIn' m ρ α d] [ForIn' n ρ α d] [ForIn Id ρ α] [Std.Internal.LawfulMemForInId ρ α] [Std.Internal.PureForIn' m ρ α] [Std.Internal.PureForIn' n ρ α] (xs : ρ) (init : β) (f : (a : α) → a ∈ xs → β → m (ForInStep β)) :