โ† back to index

Indexed Graded Monads and Their Logics

Kura, Gaboardi, Sekiyama, Unno ยท ESOP 2026 ยท arxiv arXiv:2601.14846

Prereqs: ๐Ÿž Staton 2025 (Hoare triples), ๐Ÿž Gaboardi 2021 (graded effects).

An indexed graded monad combines two ideas: the index says which type of state you start and end in (like a state machine), and the grade tracks cumulative effects. Definition 7 gives the composition rule: the output index of stage 1 must equal the input index of stage 2.

Simplifications on this page: grades are natural numbers with + as the semiring operation, indices are symbols, and logical quantification ("for all x") is demonstrated by finite test sets.

Indexing โ€” which state you're in

An indexed monad T(i, j, A) means: "a computation that starts in state i, ends in state j, and produces a value of type A." You can only compose T(i, j, _) with T(j, k, _) โ€” the output state of the first must match the input state of the second. This is the handshake.

Stage 1 post = pre j Stage 2 post = pre k Stage 3 i j k l each stage's postcondition is the next stage's precondition
raw T(i, j, A) filtered T(j, k, A) ranked output index of step 1 = input index of step 2
Scheme

Adding grades on top

Now add a grade: T(i, j, e, A) means "start in i, end in j, with effect e, producing A." Composition requires index match (handshake) AND grade composition (budget accounting). This is Definition 3 in the paper. The paper uses a preordered semiring for grades; on this page, we use (ℕ, +, 0) โ€” natural numbers with addition.

T(i, j) grade e₁ j T(j, k) grade e₂ = T(i, k) e₁ · e₂ i j must match k indices must match at boundaries; grades compose
raw i โ†’ j e=2 cached j โ†’ k e=1 filtered total grade: 2 + 1 = 3
Scheme

The restricted pointwise order

Kura's innovation: the restricted pointwise order on graded predicates. A graded predicate Q at grade e refines Q' at grade e' if e โ‰ค e' and Q(x) implies Q'(x) for all x. This lets you weaken postconditions by increasing the allowed effect budget โ€” you can always over-approximate.

x > 10, cost=1 tight, cheap x > 0, cost=3 loose, expensive tighter Q higher cost budget →
Scheme

The handshake โ€” Definition 7

Definition 7 gives the composition rule for indexed graded Hoare triples. If {P} cโ‚ : (iโ†’j, eโ‚) {R} and {R} cโ‚‚ : (jโ†’k, eโ‚‚) {Q}, then {P} cโ‚;cโ‚‚ : (iโ†’k, eโ‚ยทeโ‚‚) {Q}. The intermediate R is the handshake โ€” it must satisfy both the postcondition of cโ‚ and the precondition of cโ‚‚, at matching index j.

{P} c₁ {R} i → j, grade e₁ {R} c₂ {Q} j → k, grade e₂ j = j handshake {P} c₁;c₂ {Q} i → k, grade e₁·e₂
Scheme

Confidence: Simplified. Captures the composition law. The paper's version works over graded Freyd categories with a preordered semiring.

Graded monad lifting

The restricted pointwise order weakens postconditions: more budget, less guaranteed about the output. Lifting works the other direction. It pulls a postcondition backward through a computation to derive the weakest precondition on the input. The grade controls how much that precondition relaxes. Same monotonicity, opposite ends of the pipe.

Scheme

Notation reference

Paper Scheme Meaning
T(i, j, e, A)(make-ig i j e val)Indexed graded computation
eโ‚ ยท eโ‚‚(grade-op e1 e2)Grade composition
i = j (Def 7)(eq? (idx-end t1) (idx-start t2))Index handshake
โ‰ค_rporefines?Restricted pointwise order
wp_e(c, Q)(graded-wp c grade Q)Graded weakest precondition
Neighbors

Other paper pages

Foundations (Wikipedia)

Translation notes

All examples use simple integers for grades and symbols for indices. The paper works over preordered semirings for grades and arbitrary index categories, with the restricted pointwise order defined on fibered predicates. For example: the handshake demonstration on this page checks symbol equality between two stages. In the paper, the same definition works over a category of indexed types where the index match is a morphism equation in the index category โ€” allowing non-trivial coercions between compatible state types. The composition pattern is identical. The categorical generality is not.

Ready for the real thing? arxiv Read the paper. Start at ยง3 for indexed graded monads (Def 3), ยง4 for the Hoare logic (Def 7).

Framework connection: The Natural Framework pipeline's handshake composition maps directly to Definition 7 โ€” the output index of each stage must match the input index of the next. (jkThe Handshake)