Grade Soundness from Flexibly Graded Effect Trees
Zachery Casey, Shin-ya Katsumata, Marco Gaboardi
cs.PL
Dec 2, 2026 · v1
cs.LO
TL;DR
All results on grade soundness, the trace bound, the PCF instances and examples are mechanized in Lean 4 using only its core library.
Abstract
Graded monads attach a grade index to the monadic type of a computation to describe its computational effects. Grade soundness states that the grade of a computation bounds the computational effects it performs. We develop an operational approach to proving grade soundness in type theories with a graded monad. Our monadic small-step semantics runs a term to a tree of its executed operations. We grade the tree flexibly so that each leaf carries the grade of what remains to be run. The grade of the tree then bounds every trace through it followed by the grade of what remains at its end. We prove this bound once for any typed partially ordered monoid of grades. A type theory inherits the bound through a grade-preserving evaluation. When erasing the grades commutes with this evaluation, the bound also holds for the ungraded computation that actually runs. We instantiate the approach for a call-by-name graded monadic PCF with general recursion. It also yields effect soundness for a call-by-value type-and-effect system. Read as languages, grades contain every terminating trace. Typed grades can also enforce a lock order against deadlock or express Hoare triples. We mechanize our development in Lean 4.
Problem
Graded monads attach grades to computations to describe their effects. Grade soundness requires that a computation's grade bounds the effects it actually performs. Existing proofs are tied to a single type theory, or rely on categorical models that handle general recursion poorly.
Approach
A type-directed monadic small-step semantics runs a term to a freer-monad tree of executed operations. The tree is graded flexibly, so each leaf carries the grade of what remains to run. A trace bound is proved once for any typed partially ordered monoid of grades. Type theories inherit the bound through a grade-preserving step function, and an erasure transfers it to the ungraded computation that actually runs.
Results
The approach is instantiated for call-by-name graded monadic PCF with general recursion, an extension with grade quantification, and a call-by-value type-and-effect system. Examples cover lock-order deadlock avoidance, Hoare triples and budgets. Everything is mechanized in Lean 4, with soundness proofs translated from Agda with the help of Claude.