Combining Effects and Coeffects via Grading
Gaboardi, Katsumata, Orchard, Sato ยท ESOP 2021 ยท
arXiv:2007.06237
Prereqs: ๐ Staton 2025 (Hoare triples). 5 min.
Hoare triples with grades: a tag on every computation that tracks side effects โ how many resources it uses, how much noise it adds, how far it can branch. The grade algebra tells you what happens when you compose.
Grades track effects
A grade is an annotation on a computation. Plain Hoare logic says {P} c {Q}. Graded Hoare logic says {P} c : e {Q} โ "c has effect e." When you compose, the grades compose too: if cโ has grade eโ and cโ has grade eโ, then cโ;cโ has grade eโยทeโ (monoid multiplication).
The grade monoid
Grades form a monoid: an identity (no effect) and an associative binary operation (compose effects). Different monoids track different things.
Confidence: Simplified. Real grades are semiring-indexed, not just monoids. Same composition idea.
Graded COMP โ the handshake with budgets
Staton's COMP rule chains postconditions. Gaboardi's graded COMP chains postconditions and grades. If {P} cโ : eโ {R} and {R} cโ : eโ {Q}, then {P} cโ;cโ : eโยทeโ {Q}. The handshake carries a budget.
Graded Freyd category
The categorical setting is a graded Freyd category: a pair (C, F) where C is a category of pure values and F is a graded family of categories of effectful computations. The grading indexes which effects are allowed. Pure computations embed with grade 1 (no effect).
Confidence: Analogy. Real Freyd categories are indexed by a grading semiring. This captures the composition law but not the full categorical structure.
Effects meet coeffects
Effects track what a computation does to the world (writes, exceptions, nondeterminism). Coeffects track what it needs from the world (reads, resource usage, context). Gaboardi unifies both in one grading: the effect monoid and coeffect comonoid are two sides of the same semiring.
Notation reference
| Paper | Python | Meaning |
|---|---|---|
| {P} c : e {Q} | assert P; c(); assert Q; grade=e | Graded Hoare triple |
| eโ ยท eโ | grade_op(e1, e2) | Grade composition |
| 1 | 0 or 1.0 | Identity grade (no effect) |
| T_e | GradedComp(fn, e) | Graded monad at grade e |
| (C, F) | # pure + effectful | Graded Freyd category |
Neighbors
Other paper pages
- ๐ Staton 2025 โ ungraded Hoare logic (the starting point)
- ๐ Kura 2026 โ indexed graded monads (grading + indexing together)
- ๐ Sato 2023 โ divergences as another grading on morphism spaces
Foundations (Wikipedia)
Translation notes
All examples use simple numeric grades (counts, products). The paper works with graded monads indexed by a semiring, graded Freyd categories, and the interaction between effect and coeffect gradings via a distributive law. For example: the graded COMP on this page multiplies two fidelity floats. In the paper, the same rule works over a preordered semiring where the composition operation may be non-commutative and where the ordering constrains subeffecting (you can always over-approximate an effect grade). The composition structure is identical. The lattice-theoretic subtleties are not.
Read the paper. Start at ยง3 for graded monads, ยง5 for the graded Hoare logic.
Framework connection: The Natural Framework pipeline's composition with contracts is graded COMP โ each stage carries an effect grade that composes through the handshake. (
The Handshake,
Ambient Category)