feat(Control): free monads #53
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 261 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.333
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #53"
general
weight: 0.35
tannerduve
This PR introduces the Free monad construction for representing effectful computations as syntax trees, enabling clean separation between program syntax and interpretation semantics. Given a type constructor
F : Type ->T Typeyou get a monad "for free".Implementation: Uses the "freer monad" approach since the traditional free monad is not strictly positive and thus fails termination checking. The
FreeM F αtype represents computation trees where nodes (liftBind) are effect requests with continuations, and leaves (pure) are final values.Core contributions
Cslib/Foundations/Control/Monad/Free.lean:FreeMdefinition withFunctor/Monadinstances andLawfulFunctor/LawfulMonadproofs. Includes canonical interpreterliftMwhich is the universal morphism that uniquely defines the free monad.Cslib/Foundations/Control/Monad/Free/Fold.lean: Fold function on the free monad, and uniqueness proof of the universal property of "the unique morphism from an initial algebra" (catamorphism).Cslib/Foundations/Control/Monad/Free/Effects.lean: Standard monad implementations as free monads:-
FreeState s: State monad withget/putoperations-
FreeWriter w: Writer monad, logging computations withtelloperation-
FreeCont r: Cont monad, continuation-passing computationsCsLibTests/FreeMonad.lean: Complete verified interpreter for an expression language with state, errors, and tracing. Shows how multiple effects can be combined using sum types without monad transformers. Includes big-step operational semantics and correctness proof relating the fold-based interpreter to the semantics.Applications
Embedded DSLs, compilers and interpreters, program analysis, formalizing cryptography, formalizing computational complexity
This enables building interpreters where syntax (what effects to perform) is cleanly separated from semantics (how to interpret those effects), supporting multiple interpretations of the same programs.