Categorical Semantics of Coeffects
Prerequisites. Direct starred prerequisites: Chapter 53. No later core chapter depends on this route.
Section 53.5 interpreted three coeffect calculi in
The repetition is not the problem. The problem is that the three verifications do not compose. Nothing in them says which equations the carrier must satisfy, so a fourth instance has no specification to meet, and the soundness argument cannot be run against an unknown model. What is missing is the structure that transports a contextual requirement through substitution and composition: one operation for sequencing, one for merging, one for splitting, and the laws they obey.
This chapter states that structure, interprets the flat calculus in it, proves the soundness theorem under exactly those laws, and recovers the three concrete models as instances. It proves no theorem about the structural calculus’s operational behavior and no theorem about quantitative or graded-modal type theory; section 150.6 says where each boundary falls.
The two calculi, restated
Convention 150.1 — The frozen cards¶
Two systems of chapter 53 are used, and only these.
The flat calculus, whose judgment is
with one scalar for the whole context, and whose rules are F-Var, F-Const, F-Abs and F-App. Its scalars carry a sequential composition with unit , a sharing operation , and a meet , together with the order used by subcoeffecting.The structural calculus, whose judgment is
with one scalar per variable, and whose rules are S-Abs and S-App.
The operational hypotheses of the two cards are kept separate throughout: theorem 53.2 is a statement about call-by-value reduction with a pure-value argument, theorem 53.5 about call-by-name, and theorem 53.7 about the structural system. Nothing below transports one to another.
Referenced from 4 locations
Indexed comonads
Read a judgment
Definition 150.2 — Indexed comonad¶
Let
a family
, the counit, natural in ;for each
an operation sending a morphism to a morphism , natural in and ,
such that for all
Referenced from 4 locations
Lemma 150.3 — Composition and functor action¶
Let
Referenced from 4 locations
Proof of Lemma 150.3 — Composition and functor action
Proof. Units. For
Associativity. For
Functoriality.
Example 150.4 — Comonads are the trivial case¶
Take
Referenced from 2 locations
Example 150.5 — Liveness¶
Take
Referenced from 8 locations
Merging and splitting
Sequencing is not enough. Building a function merges the caller’s context with the argument’s; applying one splits a single context into the two the premises need. Each is an extra family of morphisms, and each carries its own index arithmetic.
Definition 150.6 — Indexed lax and colax monoidal structure¶
Let
Referenced from 11 locations
The two index operations are not interchangeable, and the reason is directional. Merging may lose part of a context, so the result is indexed by the greatest lower bound
Example 150.7 — Liveness continued¶
With the liveness algebra of example 150.5,
Referenced from 5 locations
Interpreting the flat calculus
Definition 150.8 — Interpretation¶
Fix a cartesian closed
Referenced from 8 locations
The application clause is the only one whose shape is not immediate, and it is forced. Both premises need the free variables, so the context is first duplicated inside
Theorem 150.9 — Soundness of the flat interpretation¶
Assume the associativity conditions of definition 150.6, and assume subcoeffecting
Referenced from 4 locations
Proof of Theorem 150.9 — Soundness of the flat interpretation
Proof. Induction on the derivation.
F-Var. The premise annotation is
F-Abs. By the induction hypothesis the body is a morphism
F-App. By the induction hypotheses the premises are morphisms
Subcoeffecting. The rule composes with
Well-definedness under associativity. A derivation merging, or splitting, three contexts in two different orders yields two composites differing by the associativity morphism assumed in definition 150.6; that assumption makes them equal. ◻
Remark 150.10 — What soundness does and does not give¶
Theorem 150.9 says that the interpretation is defined and independent of the derivation. It does not say that it is preserved by reduction: that is theorem 53.2 and theorem 53.5, each proved for its own reduction relation in chapter 53 and neither reproved nor strengthened here. No clause above uses the pure-value premise of the call-by-value card.
Referenced from 2 locations
Recovering the concrete models
Proposition 150.11 — The three models are instances¶
Each model of section 53.5 is an indexed comonad with the structure of definition 150.6, and its interpretation agrees with definition 150.8.
Liveness: example 150.5 and example 150.7.
Bounded reuse:
with multiplication and unit , , counit the projection at , pairing componentwise into , and splitting a tuple of length into its first and first entries.Causal dataflow:
with addition and unit , recording the current value and past ones, counit the first projection, and truncating and duplicating histories.
Referenced from 6 locations
Proof of Proposition 150.11 — The three models are instances
Proof. In each case the three laws (150.1) are checked on elements. For (2),
Exercise 150.1¶
Verify the three laws (150.1) for example 150.5 by checking all four index combinations of the third law.
Referenced from 2 locations
Exercise 150.2¶
Prove that for a one-element index monoid the operation
Referenced from 2 locations
Exercise 150.3¶
Change
Referenced from 2 locations
The structural calculus, and the boundaries
The structural judgment carries one scalar per variable, so its interpretation replaces the single index
Remark 150.12 — The structural soundness statement is separate¶
Stating the analogue of theorem 150.9 for the structural calculus needs two hypotheses that the flat statement does not: that the pointwise operations satisfy the associativity conditions componentwise, and that the interpretation is stable under exchanging two variables of a context, since the structural rules distinguish positions while the flat rules do not. Those hypotheses are local to the structural card, and no theorem of section 150.4 implies them.
Referenced from 2 locations
Remark 150.13 — The causal-dataflow boundary¶
Proposition 150.11(3) exhibits causal dataflow as an indexed comonad and does no more. Subject reduction under call-by-name holds for liveness and for bounded reuse. It fails for dataflow. An expression substituted under a binder must carry the history of the position it came from, and ordinary capture-avoiding substitution does not. So a grade algebra by itself supplies no operational semantics and no preservation theorem. The dataflow card owns its own reduction relation, and the call-by-name preservation card restated in convention 150.1 is not available for it.
Referenced from 4 locations
Remark 150.14 — Scope of the name¶
In this chapter the phrase “indexed comonadic semantics” names the two structures of definition 150.2 and definition 150.6, together with the laws (150.1) and the two associativity conditions. It names nothing else. No theorem of quantitative type theory is proved or used here, and none of graded modal type theory. No result above transfers to a calculus whose contexts carry a different notion of resource.
Referenced from 3 locations
Suggested first pass.
Begin with exercise 150.4 and exercise 150.5, then complete exercise 150.7.
Exercise 150.4¶
Complete the verification of proposition 150.11(2): write
Referenced from 3 locations
Exercise 150.5¶
Show that
Referenced from 3 locations
Exercise 150.6¶
For the dataflow model of proposition 150.11(3), take a context supplying one past value and compute
Referenced from 2 locations
Exercise 150.7¶
Practical project.indexed-comonad-law-checker Implement a checker for indexed comonads over finite sets. The input is a finite index set with multiplication tables for
Invariant. Before checking any law the program verifies that every supplied table is a total function of the declared source and target, recomputing both from the index arithmetic rather than from the table’s own extent: the source of
Concrete result. For each of the three laws of (150.1) and each of the two associativity conditions of definition 150.6, the program prints either holds or fails together with a witnessing triple of indices and an element of the source at which the two sides differ.
Acceptance test. Run it on the liveness model of example 150.5 and example 150.7 with holds. Run it on the bounded-reuse model of proposition 150.11(2) with holds for all five, and print the list of triples it skipped together with the product that left the set. A checker that silently omits those triples without reporting them is rejected by this test. Then replace
Referenced from 3 locations
Sources. Definition 150.2 is Definition 2 of T. Petricek, D. Orchard and A. Mycroft, Coeffects: unified static analysis of context-dependence, ICALP 2013 [POM13], physical page 6; lemma 150.3 collects the derived composition and functor action stated on physical pages 6–8 of the same source, and example 150.5 is its Example 2 on physical page 6. Definition 150.6 and the clauses of example 150.7 are on physical page 7; the interpretation of definition 150.8 is its Figure 5 on physical page 8; and the failure of subject reduction for dataflow recorded in remark 150.13 is the discussion following its Theorem 1 on physical page 10. The flat and structural systems restated in convention 150.1, together with the theorem cards this chapter does not reprove, are chapter 53, following Petricek, Orchard and Mycroft [POM14] and the long-form development [Pet17]. The comparison of graded and coeffectful presentations is Liepelt et al. [LMO26]; it is not used above, and remark 150.14 states what this chapter does not claim about it.