Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.
The terms 𝑒1=3,𝑒2=?𝗐𝗂𝖽𝗍𝗁+3 can have the same empty effect trace. They do not have the same contextual requirement: 𝑒2 needs a binding for the implicit parameter ?𝗐𝗂𝖽𝗍𝗁. An effect bounds what evaluation does to an environment. A coeffect bounds what evaluation requires from that environment.
Coeffect scalars and the flat judgment
A coeffect scalar structure is a tuple (C,⊛,⊕𝖼,𝗎𝗌𝖾,𝗂𝗀𝗇,≤) such that (C,⊛,𝗎𝗌𝖾) and (C,⊕𝖼,𝗂𝗀𝗇) are monoids, (C,≤) is a preorder, and sequential composition distributes over sharing on both sides: (𝑟⊕𝖼𝑠)⊛𝑡=(𝑟⊛𝑡)⊕𝖼(𝑠⊛𝑡),𝑡⊛(𝑟⊕𝖼𝑠)=(𝑡⊛𝑟)⊕𝖼(𝑡⊛𝑠). The element 𝗎𝗌𝖾 is the requirement of one variable occurrence; 𝗂𝗀𝗇 is the requirement of an unused binding. The two monoids need not be arithmetic multiplication and addition.
A flat coeffect annotates an entire variable context by one scalar. Choose an operation ∧𝖼:C×C→C satisfying 𝑟∧𝖼𝑠≤𝑟⊕𝖼𝑠.(𝐹) The flat judgment is Γ@𝖿𝑟⊢𝑒:𝜏. Function types carry a latent scalar 𝜎𝑡→𝖼𝜏. The four rules used below are
∅@𝖿𝗂𝗀𝗇⊢𝑐:𝜄
F-Const
𝑥:𝜏@𝖿𝗎𝗌𝖾⊢𝑥:𝜏
F-Var
Γ,𝑥:𝜎@𝖿(𝑟∧𝖼𝑠)⊢𝑒:𝜏
Γ@𝖿𝑟⊢𝜆𝑥.𝑒:𝜎𝑠→𝖼𝜏
F-Abs
Γ1@𝖿𝑟⊢𝑒1:𝜎𝑡→𝖼𝜏Γ2@𝖿𝑠⊢𝑒2:𝜎
Γ1,Γ2@𝖿(𝑟⊕𝖼(𝑡⊛𝑠))⊢𝑒1𝑒2:𝜏
F-App
Weakening, exchange, contraction, and subcoeffecting are admissible when the selected flat algebra validates their corresponding context transformations. Condition 𝐹 is the exact inequality used by beta preservation.
For implicit parameters take C=P(𝖭𝖺𝗆𝖾×𝖳𝗒𝗉𝖾),⊛=⊕𝖼=∧𝖼=∪,𝗎𝗌𝖾=𝗂𝗀𝗇=∅,≤=⊆. The primitive access judgment is Γ@𝖿{(?𝑝,𝜏)}⊢?𝑝:𝜏. Thus the opening terms have requirements ∅ and {(?𝗐𝗂𝖽𝗍𝗁,𝗂𝗇𝗍)}, although both are effect free.
The first theorem card uses the flat rules just printed and call-by-value beta reduction. A syntactic value 𝑣 is a pure value when it has a derivation Γ@𝖿𝗎𝗌𝖾⊢𝑣:𝜎. In the flat shape there is one scalar regardless of the number of variables in Γ.
Proof of Lemma 53.1 — Flat call-by-value substitution
Proof. Induct on the derivation of the receiving term 𝑒𝑟. In the variable case 𝑒𝑟=𝑥, the premise annotation is 𝗎𝗌𝖾, so the substituted derivation is the first hypothesis. A different variable retains its own F-Var derivation and weakens across Γ. In an abstraction, choose its binder outside fv(𝑒𝑠)∪dom(Γ1,Γ,Γ2); the induction hypothesis checks the renamed body and F-Abs restores the same immediate and latent scalars. In an application, apply the induction hypothesis to both premises in which 𝑥 occurs. Distributivity of ⊛ over ⊕𝖼 reconstructs the annotation in F-App. The context-transformation cases use the corresponding flat algebra law. These cases exhaust the derivation. ◻
Proof of Theorem 53.2 — Flat call-by-value subject reduction
Proof. The congruence cases rebuild their typing rules. For beta, invert F-App and F-Abs. The value premise has scalar 𝗎𝗌𝖾, so lemma 53.1 types the reduct. The two static context combinations differ by replacing 𝑟∧𝖼𝑠 by 𝑟⊕𝖼𝑠; condition 𝐹 and subcoeffecting give the required annotation. This is Theorem 11 of the selected calculus [POM14]. ◻
If beta contracts an arbitrary context-dependent argument, the substitution lemma’s pure-value premise is false. The call-by-value theorem therefore does not justify call-by-name evaluation.
The flat call-by-name card
The second card keeps the flat typing rules but changes the reduction relation. A flat algebra is top-pointed when 𝑠≤𝗎𝗌𝖾 for every 𝑠∈C. It is bottom-pointed when 𝗎𝗌𝖾≤𝑠 for every 𝑠∈C.
Assume the flat algebra is bottom-pointed and ∧𝖼=⊛=⊕𝖼, with this common operation commutative and idempotent. If Γ@𝖿𝑠⊢𝑒𝑠:𝜎 and Γ1,𝑥:𝜎,Γ2@𝖿𝑟⊢𝑒𝑟:𝜏, then Γ1,Γ,Γ2@𝖿(𝑟⊛𝑠)⊢𝑒𝑟[𝑒𝑠/𝑥]:𝜏.
Proof. Induct on the receiving derivation. The 𝑥-case uses 𝗎𝗌𝖾≤𝑠 and subcoeffecting. Application combines each copy of the substituted requirement with the surrounding requirement. Commutativity reassociates 𝑠 with the free-variable context; idempotence merges repeated copies introduced by contraction. Abstraction preserves that combined requirement because ∧𝖼=⊛=⊕𝖼. ◻
Proof of Theorem 53.5 — Flat call-by-name subject reduction
Proof. Congruence preserves the derivation. In the beta case, inversion of F-App and F-Abs produces the premises of the appropriate substitution lemma. The top-pointed lemma retains 𝑟. In the bottom-pointed case, the equality of the three operations and idempotence reduce the substituted annotation to the one in the application conclusion. This is the two-case hypothesis of source Theorem 14 [POM14], not a result for an arbitrary flat algebra. ◻
The implicit-parameter instance is bottom-pointed under inclusion because 𝗎𝗌𝖾=∅, and its three operations are set union. Hence the call-by-name theorem applies. Flat liveness instead uses a greatest 𝗎𝗌𝖾 and belongs to the top-pointed case.
★★☆ Give a three-element preorder in which 𝗎𝗌𝖾 is neither greatest nor least. Explain why neither call-by-name substitution lemma applies; do not infer that subject reduction fails without constructing a calculus and a counterexample.
A structural coeffect assigns one scalar to each variable. A context 𝑥1:𝜏1,…,𝑥𝑛:𝜏𝑛 carries a vector 𝑅=⟨𝑟1,…,𝑟𝑛⟩∈C𝑛. The empty vector is ⟨⟩, vector concatenation is 𝑅++𝑆, and scalar multiplication is pointwise: 𝑟⊛⟨𝑠1,…,𝑠𝑛⟩=⟨𝑟⊛𝑠1,…,𝑟⊛𝑠𝑛⟩. The judgment is Γ@𝗌𝑅⊢𝑒:𝜏. Its abstraction and application rules are
Γ,𝑥:𝜎@𝗌(𝑅++⟨𝑠⟩)⊢𝑒:𝜏
Γ@𝗌𝑅⊢𝜆𝑥.𝑒:𝜎𝑠→𝖼𝜏
S-Abs
Γ1@𝗌𝑅⊢𝑒1:𝜎𝑡→𝖼𝜏Γ2@𝗌𝑆⊢𝑒2:𝜎
Γ1,Γ2@𝗌(𝑅++(𝑡⊛𝑆))⊢𝑒1𝑒2:𝜏
S-App
Variables carry ⟨𝗎𝗌𝖾⟩. Weakening appends ⟨𝗂𝗀𝗇⟩. Exchange swaps a variable and its scalar. Contraction replaces adjacent scalars 𝑟,𝑠 by 𝑟⊕𝖼𝑠. Write Γ′@𝗌𝑅′⇝𝖼𝗍𝗑,𝜃Γ@𝗌𝑅 for the context-transformation package generated by these four operations. The package is locally sound when every generator transforms a typing derivation as stated, and locally complete when every weakening, adjacent permutation, adjacent identification, or pointwise increase used in a derivation factors through those generators. The structural card assumes both properties, together with the two scalar monoids and both distributivity equations from section 53.1. This states exactly what the contextual rule may do; it is not an unrestricted structural congruence.
Proof. Induct on the receiving derivation. The variable case 𝑥 has 𝑟=𝗎𝗌𝖾, and the sequential monoid identity gives 𝗎𝗌𝖾⊛𝑆=𝑆. Abstraction extends both the context and vector at the same end; alpha-renaming chooses its binder outside fv(𝑒𝑠)∪dom(Γ1,Γ,Γ2). Application substitutes into each premise and uses distributivity to combine multiple occurrences. Weakening, exchange, and contraction transform the variable and its scalar together; the stated local soundness/completeness conditions reconstruct those rules. No flat operation ∧𝖼 occurs. ◻
Proof of Theorem 53.7 — Structural subject reduction
Proof. The beta case inverts S-App and S-Abs; the bound variable occupies one unique vector position. Applying lemma 53.6 replaces its scalar 𝑟 by 𝑟⊛𝑆, exactly the vector printed by S-App. Congruence cases rebuild their derivations. Context conversions before or after the redex are transported by local soundness and completeness of weakening, exchange, and contraction. This is source Theorem 8 at the structural signature [POM14]. ◻
For bounded reuse choose (ℕ,×,+,1,0,≤). The term 𝜆𝑥.𝑥+𝑥 assigns latent grade 2 to 𝑥, because the two occurrences contract 1+1. Applying it to 𝑦, whose vector is ⟨1⟩, produces 2×⟨1⟩=⟨2⟩. This is a contextual demand on 𝑦, not a claim that evaluation performs two effects.
★☆☆ Derive the vector for (𝜆𝑥.𝑥+𝑥)(𝑦+𝑦). Show separately the contraction that gives the latent 2 and the multiplication that scales the argument vector.
The implicit-parameter model can be constructed without categorical machinery. Regard every object 𝐴 as a set. A requirement set is well formed when it assigns at most one type to each name. A finite typed dictionary 𝜌realizes𝑅, written 𝜌⊧𝖽𝑅, when 𝜌(?𝑝)∈𝜏 for every (?𝑝,𝜏)∈𝑅. Let 𝐷𝑅(𝐴)={(𝜌,𝑎)∣𝜌isafinitetypeddictionary,𝜌⊧𝖽𝑅,𝑎∈𝐴}. For 𝑅⊆𝑆, let 𝜌|𝑅 retain exactly the dictionary entries named in 𝑅, and define the requirement-forgetting map res𝑆𝑅:𝐷𝑆(𝐴)⟶𝐷𝑅(𝐴),res𝑆𝑅(𝜌,𝑎)=(𝜌|𝑅,𝑎). If (𝜌,(𝑎,𝑏))∈𝐷𝑅∪𝑆(𝐴×𝐵), then (𝜌,(𝑎,𝑏))⟶((𝜌|𝑅,𝑎),(𝜌|𝑆,𝑏))∈𝐷𝑅(𝐴)×𝐷𝑆(𝐵). The two restricted dictionaries are available because 𝜌 realizes every entry in 𝑅∪𝑆. For an access (?𝑝), the map sends (𝜌,∗) to 𝜌(?𝑝); its domain condition is exactly (?𝑝,𝜏)∈𝑅.
The bounded-reuse model is also concrete. For 𝑅=⟨𝑟1,…,𝑟𝑛⟩, set 𝐵𝑅(𝐴1,…,𝐴𝑛)=𝐴𝑟11×⋯×𝐴𝑟𝑛𝑛. The variable rule selects the sole component of 𝐴1. Contraction uses the canonical regrouping 𝐴𝑟×𝐴𝑠≅𝐴𝑟+𝑠. Substitution uses (𝐴𝑠)𝑟≅𝐴𝑟×𝑠, which is the semantic counterpart of the grade 𝑟⊛𝑠 in lemma 53.6.
Causal dataflow needs a different operational account. Let a stream environment 𝜌 map each 𝑥 to values 𝜌(𝑥)0,𝜌(𝑥)1,…. The dedicated lookup rule is ⟨𝗉𝗋𝖾𝗏𝑘𝑥,𝜌,𝑛⟩⟶𝖽𝖿𝜌(𝑥)𝑛−𝑘(𝑘≤𝑛). A structural vector 𝑅 is sound for this lookup fragment when every occurrence 𝗉𝗋𝖾𝗏𝑘𝑥𝑖 has 𝑘≤𝑅𝑖. Ordinary syntactic substitution is unsuitable as the operational definition: replacing 𝑥 by an arbitrary stream expression can duplicate or shift the history demanded by that expression, whereas the machine rule reads a named stream at an explicit time index. The chapter therefore claims only the displayed lookup bound and its immediate closure under arithmetic contexts. It does not claim an independent progress, preservation, or cache-optimality theorem for a complete dataflow language.
The non-transfer boundary can now be read without identifying the cards:
card
local hypothesis and non-transfer boundary
flat value
One scalar and an argument at 𝗎𝗌𝖾 and 𝐹 do not give arbitrary call-by-name preservation.
flat name
Top-pointedness, or bottom-pointedness with the three operations equal, commutative, and idempotent, does not give structural substitution.
structural
One scalar per variable and locally sound and complete structural operations do not give either pointed flat theorem.
dataflow lookup
A history bound for each stream and a named lookup with 𝑘≤𝑛 do not give whole-language subject reduction.
The dictionary and finite-power constructions prove only the displayed local Set calculations. They do not yet supply the indexed comonad, its counit and comultiplication, or the coherence equations needed for a categorical model of all three cards. That construction must wait until those categorical notions have been developed.
Sources.
The earlier unified flat calculus introduces implicit parameters, liveness, and dataflow under one whole-context annotation and supplies the indexed comonadic account [POM13]. It is provenance for the flat motivation, not for the later structural theorem. The archived Petricek–Orchard–Mycroft PDF pages 4–6 print Definitions 1–5 and the structural and flat instances; pages 7–8 print structural substitution, Theorems 8, 11, and 14, and their exact call-by-value, top-pointed, and bottom-pointed hypotheses [POM14]. The longer thesis supplies worked implicit-parameter and dataflow derivations, not a license to move results between the cards [Pet17].
★★☆ For one beta redex, write the substitution premise and conclusion separately for flat call-by-value, top-pointed flat call-by-name, bottom-pointed flat call-by-name, and structural call-by-name. Circle the hypothesis that differs in each row.
★★☆ For 𝑅={(?𝑤,𝗂𝗇𝗍)} and 𝑆={(?ℎ,𝗂𝗇𝗍)}, construct an element 𝑑 of 𝐷𝑅∪𝑆(𝗂𝗇𝗍×𝗂𝗇𝗍) and compute its split image in 𝐷𝑅(𝗂𝗇𝗍)×𝐷𝑆(𝗂𝗇𝗍). Separately compute res𝑅∅(res𝑅∪𝑆𝑅(𝑑)) and the path through 𝑆. That second path is res𝑆∅(res𝑅∪𝑆𝑆(𝑑)). Prove that both are the same element of 𝐷∅(𝗂𝗇𝗍×𝗂𝗇𝗍) by proving the needed restriction equation.
★★☆ For 𝑒=𝗉𝗋𝖾𝗏2𝑥+(𝗉𝗋𝖾𝗏1𝑦+𝗉𝗋𝖾𝗏3𝑥), compute the least cache vector. Evaluate 𝑒 at time 𝑛=3 in a symbolic stream environment and list the three entries read.
★★★Practical project.coeffect-demand-checker Implement implicit-parameter union and structural bounded-reuse inference in Kappa. Maintain the invariant that flat requirements contain every accessed name and that each structural counter equals the syntax-directed occurrence count. The accepted run must report the opening requirements, count (𝑥+𝑥)+(𝑥+𝑦) as 𝑥↦3,𝑦↦1, and validate the substitution calculation 2×2=4. Mutate contraction from addition to maximum: the mutant must typecheck and audit cleanly but fail the repeated-use oracle. Use artifacts/ch53-coeffect-context/corpus.kp; the accepted run must end with All 5 coeffect corpus cases passed. The program illustrates the two Set calculations and structural substitution; it does not prove any subject-reduction theorem.