Cslib.FreeM.FreeWriter.run
defimported Lean
Interprets a FreeWriter computation by recursively traversing the tree, accumulating log entries with the monoid operation, and returns the final value paired with the accumulated log.
Statement
set_option autoImplicit true in set_option relaxedAutoImplicit true in open Cslib Cslib.FreeM in universe u v w w' w'' in open WriterF in variable {ω : Type u} {α β : Type*} in def Cslib.FreeM.FreeWriter.run [Monoid ω] : FreeWriter ω α → α × ω
- Defined in
- CSLib, `Cslib.FreeM.FreeWriter.run`
- 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.FreeWriter.run← Cslib.FreeM.FreeWriter.run (Cslib/Foundations/Control/Monad/Free/Effects.lean:207): verbatim
- Verified
- 08 Oct 2026
- Axioms
- none listed
- Built on 29
- Cslib.FreeM.FreeWriter.writerInterpInterpret
WriterFoperations intoWriterT. - Cslib.FreeM.liftM_seqLeftCslib.FreeM.liftM_seqLeft
- Cslib.FreeM.liftM_bindCslib.FreeM.liftM_bind
- Cslib.FreeM.FreeWriter.tell_defCslib.FreeM.FreeWriter.tell_def
- Cslib.FreeM.liftM_seqRightCslib.FreeM.liftM_seqRight
- Cslib.FreeM.liftM_liftCslib.FreeM.liftM_lift
- Cslib.FreeM.liftM_seqCslib.FreeM.liftM_seq
- Cslib.FreeM.liftM_mapCslib.FreeM.liftM_map
- Cslib.FreeM.FreeWriterWriter monad implemented via the
FreeMmonad construction. This provides a more efficient implementation than the traditionalWriterT… - 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.WriterFType constructor for writer operations. Writer has a single effect, so the definition has just one constructor.
- 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.instPureCslib.FreeM.instPure
- 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
- Cslib.FreeM.FreeWriter.writerInterpInterpret
- Used by 8
- Cslib.FreeM.FreeWriter.pass_defCslib.FreeM.FreeWriter.pass_def
- Cslib.FreeM.FreeWriter.pass
passallows a subcomputation to modify its own log. After traversing the computation and accumulating its log, the resulting function is… - Cslib.FreeM.FreeWriter.run_lift_tellCslib.FreeM.FreeWriter.run_lift_tell
- Cslib.FreeM.FreeWriter.run_bindCslib.FreeM.FreeWriter.run_bind
- Cslib.FreeM.FreeWriter.run_pureCslib.FreeM.FreeWriter.run_pure
- Cslib.FreeM.FreeWriter.listen
listencaptures the log produced by a subcomputation incrementally. It traverses the computation, emitting log entries as encountered,… - Cslib.FreeM.FreeWriter.listen_lift_tell_bindCslib.FreeM.FreeWriter.listen_lift_tell_bind
- Cslib.FreeM.FreeWriter.run_toWriterTThe canonical interpreter
toWriterTderived fromliftMagrees with the hand-written recursive interpreterrunforFreeWriter.
Lean source view module on GitHub
set_option autoImplicit true in set_option relaxedAutoImplicit true in open Cslib Cslib.FreeM in universe u v w w' w'' in open WriterF in variable {ω : Type u} {α β : Type*} in /-- Interprets a `FreeWriter` computation by recursively traversing the tree, accumulating log entries with the monoid operation, and returns the final value paired with the accumulated log. -/ def Cslib.FreeM.FreeWriter.run [Monoid ω] : FreeWriter ω α → α × ω | .pure a => (a, 1) | .liftBind (.tell w) k => let (a, w') := run (k .unit) (a, w * w')