Cslib.FreeM.foldFreeM_unique
theoremverifiedformalizationimported Lean
Universal Property: If h : FreeM F α → β satisfies: * h (pure a) = onValue a * h ((lift op).bind k) = onEffect op (fun x => h (k x)) then h is equal to foldFreeM onValue onEffect.
Statement
set_option autoImplicit true in set_option relaxedAutoImplicit true in universe u v w w' in variable {F : Type u → Type v} {ι : Type u} {α : Type w} {β : Type w'} in theorem Cslib.FreeM.foldFreeM_unique (onValue : α → β) (onEffect : {ι : Type u} → F ι → (ι → β) → β) (h : FreeM F α → β) (h_pure : ∀ a, h (pure a) = onValue a) (h_liftBind : ∀ {ι} (op : F ι) (k : ι → FreeM F α), h ((lift op).bind k) = onEffect op (fun x => h (k x))) : h = foldFreeM onValue onEffect
- Formalizes
- CSLib, `Cslib.FreeM.foldFreeM_unique`
- Lean proof
- By Tanner Duve, from github.com/leanprover/cslib at
3951377e5a3f(Copyright (c) 2025 Tanner Duve. All rights reserved, Apache-2.0). Compiled here against leanprover/lean4:v4.33.1, Mathlib v4.33.1; written for leanprover/lean4:v4.33.0.Cslib.FreeM.foldFreeM_unique← Cslib.FreeM.foldFreeM_unique (Cslib/Foundations/Control/Monad/Free/Fold.lean:95): verbatim
- Verified
- 08 Oct 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 33
- Cslib.FreeM.liftM_seqLeftCslib.FreeM.liftM_seqLeft
- Cslib.FreeM.liftM_bindCslib.FreeM.liftM_bind
- Cslib.FreeM.foldFreeM_lift_bindCslib.FreeM.foldFreeM_lift_bind
- Cslib.FreeM.foldFreeM_lift_bind'Cslib.FreeM.foldFreeM_lift_bind'
- Cslib.FreeM.liftM_seqRightCslib.FreeM.liftM_seqRight
- Cslib.FreeM.liftM_liftCslib.FreeM.liftM_lift
- Cslib.FreeM.liftM_seqCslib.FreeM.liftM_seq
- Cslib.FreeM.foldFreeM_liftCslib.FreeM.foldFreeM_lift
- Cslib.FreeM.liftM_mapCslib.FreeM.liftM_map
- Cslib.FreeMThe Free monad over a type constructor
F. AFreeM F ais a tree of operations from the type constructorF, with leaves of typea.… - Cslib.FreeM.instPureCslib.FreeM.instPure
- Cslib.FreeM.bindBind operation for the
FreeMmonad. The builtin>>=notation should be preferred whenαandβare in the same universe. - Cslib.FreeM.liftLift an operation from the effect signature
Finto theFreeM Fmonad. - Cslib.FreeM.foldFreeMFold function for the
FreeMmonad - Cslib.FreeM.inductionAn override for the default induction principle that is in simp-normal form. Note that when
αandιare in the same universe, this… - Cslib.FreeM.foldFreeM_pureCslib.FreeM.foldFreeM_pure
- Cslib.FreeM.pure_eq_pureCslib.FreeM.pure_eq_pure
- Cslib.FreeM.bind_eq_bindNote that this lemma does not always apply, as it is universe-constrained by
Bind.bind. - Cslib.FreeM.map_eq_mapNote that this lemma does not always apply, as it is universe-constrained by
Functor.map. - Cslib.FreeM.liftBind_eqCslib.FreeM.liftBind_eq
- Cslib.FreeM.pure_bind
.pure afollowed bybindcollapses immediately. - Cslib.FreeM.bind_pureCslib.FreeM.bind_pure
- Cslib.FreeM.bind_pure_compCslib.FreeM.bind_pure_comp
- Cslib.FreeM.map_pureCslib.FreeM.map_pure
- Cslib.FreeM.map_bindCslib.FreeM.map_bind
- Cslib.FreeM.id_mapCslib.FreeM.id_map
- Cslib.FreeM.liftM_pureCslib.FreeM.liftM_pure
- Cslib.FreeM.liftM_lift_bindCslib.FreeM.liftM_lift_bind
- Cslib.FreeM.instBindCslib.FreeM.instBind
- Cslib.FreeM.instFunctorCslib.FreeM.instFunctor
- Cslib.FreeM.instLawfulFunctorCslib.FreeM.instLawfulFunctor
- Cslib.FreeM.instMonadCslib.FreeM.instMonad
- Cslib.FreeM.instLawfulMonadCslib.FreeM.instLawfulMonad
Lean source view module on GitHub
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
set_option autoImplicit true inset_option relaxedAutoImplicit true inuniverse u v w w' invariable {F : Type u → Type v} {ι : Type u} {α : Type w} {β : Type w'} in/-- **Universal Property**: If `h : FreeM F α → β` satisfies: * `h (pure a) = onValue a` * `h ((lift op).bind k) = onEffect op (fun x => h (k x))` then `h` is equal to `foldFreeM onValue onEffect`. -/theorem Cslib.FreeM.foldFreeM_unique (onValue : α → β) (onEffect : {ι : Type u} → F ι → (ι → β) → β) (h : FreeM F α → β) (h_pure : ∀ a, h (pure a) = onValue a) (h_liftBind : ∀ {ι} (op : F ι) (k : ι → FreeM F α), h ((lift op).bind k) = onEffect op (fun x => h (k x))) : h = foldFreeM onValue onEffect := by funext x induction x with | pure a => rw [foldFreeM_pure, h_pure] | lift_bind op k ih => rw [foldFreeM_lift_bind, h_liftBind] grind