Mendler Recursion, Nested Datatypes, and Mixed Variance
Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.
For an ordinary fixed point 𝜇𝐹, a fold first maps its recursive function over one 𝐹-layer and then applies an algebra. That recipe assumes a map operation for 𝐹. It fails twice in the developments of this chapter. A nested datatype changes its parameter at a recursive occurrence, so one endofunctor 𝐹:U𝑖→U𝑖 is not enough. A mixed-variance operator may place its argument to the left of an arrow, so it has no covariant map at all. Mendler’s repair does not give the recursive layer a map. It gives the algebra a polymorphic recursive-call argument whose abstract domain prevents the algebra from applying recursion to a value it has constructed itself.
The recursive call is abstract
First freeze the rank-zero interface. Let 𝐹:U𝑖→U𝑖 be a type operator and assume a carrier 𝜇𝖬𝐹:U𝑖 with constructor 𝗂𝗇𝖬𝐹:𝐹(𝜇𝖬𝐹)→𝜇𝖬𝐹. This is a selected Mendler fixed-point interface, not the ordinary strictly positive fixed point of chapter 80. No destructor is available.
The complete interface appears in the fixed order formation, introduction, elimination, computation:
Γ⊢𝐹:U𝑖→U𝑖
Γ⊢𝜇𝖬𝐹:U𝑖
Mendler-form
Γ⊢𝑢:𝐹(𝜇𝖬𝐹)
Γ⊢𝗂𝗇𝖬𝐹(𝑢):𝜇𝖬𝐹
Mendler-intro
Γ⊢𝐴:U𝑖Γ⊢𝜙:∏𝑅:U𝑖(𝑅→𝐴)→𝐹(𝑅)→𝐴
Γ⊢𝗆𝖿𝗈𝗅𝖽𝐹(𝜙):𝜇𝖬𝐹→𝐴
Mendler-elim
Γ⊢𝜙:∏𝑅:U𝑖(𝑅→𝐴)→𝐹(𝑅)→𝐴Γ⊢𝑢:𝐹(𝜇𝖬𝐹)
𝗆𝖿𝗈𝗅𝖽𝐹(𝜙)(𝗂𝗇𝖬𝐹(𝑢))≡𝜙(𝜇𝖬𝐹,𝗆𝖿𝗈𝗅𝖽𝐹(𝜙),𝑢):𝐴
Mendler-β
The interface deliberately contains no positivity premise and no 𝐹-action. Its normalization claim is therefore not inherited from the strictly positive fixed points of chapter 80; it is the selected metatheorem stated below.
For 𝐴:U𝑖, a Mendler algebra is a term of type 𝖬𝖠𝗅𝗀(𝐹,𝐴):=∏𝑅:U𝑖(𝑅→𝐴)→𝐹(𝑅)→𝐴. Its first argument 𝑅 is abstract. Its second argument is the only recursive call available while processing a layer 𝐹(𝑅).
For 𝜙:𝖬𝖠𝗅𝗀(𝐹,𝐴), the iterator 𝗆𝖿𝗈𝗅𝖽𝐹(𝜙):𝜇𝖬𝐹→𝐴 satisfies the computation equation 𝗆𝖿𝗈𝗅𝖽𝐹(𝜙)(𝗂𝗇𝖬𝐹(𝑢))≡𝜙(𝜇𝖬𝐹,𝗆𝖿𝗈𝗅𝖽𝐹(𝜙),𝑢). The rule is available only at the selected fixed-point signature.
No 𝗆𝖺𝗉𝐹 occurs in (84.1). This is the first gain: the algebra itself decides where its 𝑅-values occur. The universal quantifier is the second gain. A definition of 𝜙 must work for every 𝑅, so it cannot assume 𝑅=𝜇𝖬𝐹, inspect an 𝑅-value, or pass a freshly constructed 𝜇𝖬𝐹 value to the recursive call 𝑅→𝐴.
For the list base operator 𝐹𝐴(𝑅):=𝟏+(𝐴×𝑅), define 𝜙𝗅𝖾𝗇𝗀𝗍𝗁(𝑅,rec,𝗂𝗇𝗅(⋆)):=𝟢,𝜙𝗅𝖾𝗇𝗀𝗍𝗁(𝑅,rec,𝗂𝗇𝗋((𝑎,𝑟))):=𝗌𝗎𝖼(rec(𝑟)). Then 𝗆𝖿𝗈𝗅𝖽𝐹𝐴(𝜙𝗅𝖾𝗇𝗀𝗍𝗁)(𝗂𝗇𝖬𝐹𝐴(𝗂𝗇𝗋(𝑎,𝗂𝗇𝖬𝐹𝐴(𝗂𝗇𝗅⋆))))(84.1)≡𝗌𝗎𝖼(𝗆𝖿𝗈𝗅𝖽𝐹𝐴(𝜙𝗅𝖾𝗇𝗀𝗍𝗁)(𝗂𝗇𝖬𝐹𝐴(𝗂𝗇𝗅⋆)))(84.1)≡𝗌𝗎𝖼(𝟢).
Suppose 𝐹 has an action 𝗆𝖺𝗉𝐹 and let 𝛼:𝐹(𝐴)→𝐴. Put 𝜙𝛼(𝑅,rec,𝑢):=𝛼(𝗆𝖺𝗉𝐹(rec,𝑢)). Then 𝜙𝛼:𝖬𝖠𝗅𝗀(𝐹,𝐴), and its Mendler equation is the ordinary fold equation.
Proof of Proposition 84.3 — Ordinary folds are Mendler folds
Proof. For arbitrary 𝑅, the action sends 𝑢:𝐹(𝑅) and rec:𝑅→𝐴 to 𝗆𝖺𝗉𝐹(rec,𝑢):𝐹(𝐴). Applying 𝛼 gives 𝐴. Substitution in (84.1) yields 𝗆𝖿𝗈𝗅𝖽𝐹(𝜙𝛼)(𝗂𝗇𝖬𝐹(𝑢))≡𝛼(𝗆𝖺𝗉𝐹(𝗆𝖿𝗈𝗅𝖽𝐹(𝜙𝛼),𝑢)), the ordinary fold equation. ◻
The converse does not hold for an arbitrary 𝐹: a Mendler algebra can use the known constructors of 𝐹(𝑅) without supplying a map for all functions 𝑅→𝑅′. This is why the presentation remains meaningful at selected mixed-variance operators.
★☆☆ For 𝑓:𝐴→𝐵, define a Mendler algebra with result 𝜇𝖬𝐹𝐵 that maps every list element by 𝑓. Expand (84.1) at nil and cons, including the type of the recursive argument in the cons clause.
If negative recursive occurrences are admitted together with an unrestricted destructor, termination fails without any value-level recursive definition. Consider the equations 𝑇≃(𝑇→𝟏),𝖢:(𝑇→𝟏)→𝑇,𝗈𝗎𝗍:𝑇→(𝑇→𝟏). Define 𝑤(𝑥):=𝗈𝗎𝗍(𝑥)(𝑥) and 𝜔:=𝖢(𝑤). Then 𝑤(𝜔)𝗈𝗎𝗍(𝖢(𝑤))≡𝑤⟶𝑤(𝜔). The cycle is generated by the negative occurrence of 𝑇 in 𝑇→𝟏.
Now retain only the Mendler constructor for 𝐹𝖳(𝑅):=𝑅→𝟏. To recover the destructor, one would need a Mendler algebra with result 𝜇𝖬𝐹𝖳→𝟏: 𝜙:∏𝑅:U𝑖(𝑅→(𝜇𝖬𝐹𝖳→𝟏))→(𝑅→𝟏)→(𝜇𝖬𝐹𝖳→𝟏). Given 𝑓:𝑅→𝟏, the attempted clause returns 𝑓. Its required type is 𝜇𝖬𝐹𝖳→𝟏. The two domains are 𝑅 and 𝜇𝖬𝐹𝖳, and the universal 𝑅 cannot be converted to the fixed point. The self-application program therefore fails at the exact place where it would export the negative embedded function.
In a parametric model of definition 84.1, a Mendler algebra cannot apply its recursive argument rec:𝑅→𝐴 to a value whose type is not obtained as an 𝑅-component of its input 𝑢:𝐹(𝑅).
Proof. Relate an arbitrary 𝑅 to a one-point copy 𝑅′ by a relation that contains exactly the 𝑅-components selected from 𝑢. Parametricity of 𝜙:∏𝑅:U𝑖(𝑅→𝐴)→𝐹(𝑅)→𝐴 requires its result to be invariant under this relation. A call rec(𝑟) is related only when 𝑟 belongs to the selected 𝑅-components. A value constructed at the fixed point has no related 𝑅′ witness, because 𝑅 is abstract. Hence such a call would violate the relational interpretation of the universal quantifier. ◻
The lemma depends on the parametric model of the universal quantifier. It is not a syntactic theorem about every host language with a rank-polymorphic type. Abel, Matthes, and Uustalu embed their precise Mendler systems in a strongly normalizing 𝐹𝜔 calculus and obtain strong normalization at that signature [AMU05].
Every well-typed term of the rank-zero Mendler iteration calculus frozen by Abel, Matthes, and Uustalu is strongly normalizing. The result extends to their displayed higher-kinded generalized iteration schemes through their translation into 𝐹𝜔.
Proof of Theorem 84.5 — Mendler iteration normalization, imported
Imported proof. The theorem covers that calculus. It does not cover arbitrary primitive recursion, destructors, histomorphisms, dependent eliminators, or host-language effects. The translation and normalization proof are on pp. 27–35 of [AMU05]. ◻
★★☆ Write the full attempted algebra for 𝗈𝗎𝗍:𝜇𝖬𝐹𝖳→(𝜇𝖬𝐹𝖳→𝟏). Annotate the extracted function 𝑓 and the expected result with their domains. Show that replacing the result by the constant function 𝜆𝑥.⋆ typechecks and explain why it cannot recreate the reduction cycle.
A lambda binder changes the type of variables in its body. Let 𝖨𝗇𝖼𝗋(𝐴):=𝟏+𝐴 with constructors 𝗓𝖾𝗋𝗈𝖵:=𝗂𝗇𝗅(⋆) and 𝗌𝗎𝖼𝖵(𝑎):=𝗂𝗇𝗋(𝑎). Define the nested family 𝖳𝖾𝗋𝗆(𝐴)::=𝗏𝖺𝗋(𝑎)∣𝖺𝗉𝗉(𝑡,𝑢)∣𝗅𝖺𝗆(𝑏),𝑎:𝐴,𝑡,𝑢:𝖳𝖾𝗋𝗆(𝐴),𝑏:𝖳𝖾𝗋𝗆(𝖨𝗇𝖼𝗋(𝐴)). The recursive occurrence in the lambda constructor is at a different parameter. Thus 𝖳𝖾𝗋𝗆 is a nested datatype: its family members are defined together, and one constructor moves from 𝐴 to 𝖨𝗇𝖼𝗋(𝐴).
An ordinary fold to one fixed result type loses the changing parameter. The result must itself be a family 𝑁:U𝑖→U𝑖, and every method must be polymorphic in the variable type.
Let 𝑀,𝑁:U𝑖→U𝑖. Suppose 𝑣:∏𝐴:U𝑖𝑀(𝐴)→𝑁(𝐴),𝑎:∏𝐴:U𝑖𝑁(𝐴)×𝑁(𝐴)→𝑁(𝐴),𝑙:∏𝐴:U𝑖𝑁(𝖨𝗇𝖼𝗋(𝐴))→𝑁(𝐴),𝑘:∏𝐴:U𝑖𝖨𝗇𝖼𝗋(𝑀(𝐴))→𝑀(𝖨𝗇𝖼𝗋(𝐴)). Define 𝗀𝖿𝗈𝗅𝖽(𝑣,𝑎,𝑙,𝑘):∏𝐵:U𝑖𝖳𝖾𝗋𝗆(𝑀(𝐵))→𝑁(𝐵) by 𝗀𝖿𝗈𝗅𝖽(𝗏𝖺𝗋(𝑥)):=𝑣(𝑥),𝗀𝖿𝗈𝗅𝖽(𝖺𝗉𝗉(𝑡,𝑢)):=𝑎(𝗀𝖿𝗈𝗅𝖽(𝑡),𝗀𝖿𝗈𝗅𝖽(𝑢)),𝗀𝖿𝗈𝗅𝖽(𝗅𝖺𝗆(𝑏)):=𝑙(𝗀𝖿𝗈𝗅𝖽(𝗋𝖾𝗇𝖺𝗆𝖾(𝑘,𝑏))). The omitted parameters 𝑣,𝑎,𝑙,𝑘 and the ambient type are unchanged in each recursive call.
The map 𝑘 reconciles the two ways to extend the variable parameter: 𝖨𝗇𝖼𝗋(𝑀(𝐴)) and 𝑀(𝖨𝗇𝖼𝗋(𝐴)). Without it, the lambda clause is ill typed. Bird and Paterson derive this generalized fold and its naturality/fusion laws at the same nested representation [BP99].
For ordinary renaming, take 𝑀 and 𝑁 to be the identity family. Define 𝗅𝗂𝖿𝗍(𝑓)(𝗓𝖾𝗋𝗈𝖵):=𝗓𝖾𝗋𝗈𝖵,𝗅𝗂𝖿𝗍(𝑓)(𝗌𝗎𝖼𝖵(𝑎)):=𝗌𝗎𝖼𝖵(𝑓(𝑎)), and define 𝗋𝖾𝗇𝖺𝗆𝖾(𝑓,𝗏𝖺𝗋(𝑎)):=𝗏𝖺𝗋(𝑓(𝑎)),𝗋𝖾𝗇𝖺𝗆𝖾(𝑓,𝖺𝗉𝗉(𝑡,𝑢)):=𝖺𝗉𝗉(𝗋𝖾𝗇𝖺𝗆𝖾(𝑓,𝑡),𝗋𝖾𝗇𝖺𝗆𝖾(𝑓,𝑢)),𝗋𝖾𝗇𝖺𝗆𝖾(𝑓,𝗅𝖺𝗆(𝑏)):=𝗅𝖺𝗆(𝗋𝖾𝗇𝖺𝗆𝖾(𝗅𝗂𝖿𝗍(𝑓),𝑏)). The lambda equation is the first nonuniform recursive call: its function has changed from 𝑓:𝐴→𝐵 to 𝗅𝗂𝖿𝗍(𝑓):𝖨𝗇𝖼𝗋(𝐴)→𝖨𝗇𝖼𝗋(𝐵).
Proof. Use nested induction, strengthening the claim to every variable type 𝐴. The variable case is beta equality. The application case follows by the two induction hypotheses and congruence for 𝖺𝗉𝗉. In the lambda case, the induction hypothesis at 𝖨𝗇𝖼𝗋(𝐴) gives 𝗋𝖾𝗇𝖺𝗆𝖾(𝗅𝗂𝖿𝗍(𝑔),𝗋𝖾𝗇𝖺𝗆𝖾(𝗅𝗂𝖿𝗍(𝑓),𝑏))=𝗋𝖾𝗇𝖺𝗆𝖾(𝗅𝗂𝖿𝗍(𝑔)∘𝗅𝗂𝖿𝗍(𝑓),𝑏). Case analysis on 𝗓𝖾𝗋𝗈𝖵 and 𝗌𝗎𝖼𝖵(𝑎) proves 𝗅𝗂𝖿𝗍(𝑔)∘𝗅𝗂𝖿𝗍(𝑓)=𝗅𝗂𝖿𝗍(𝑔∘𝑓) pointwise. Congruence for 𝗋𝖾𝗇𝖺𝗆𝖾(−,𝑏) and then 𝗅𝖺𝗆 closes the case. ◻
★☆☆ Prove 𝗋𝖾𝗇𝖺𝗆𝖾(𝜆𝑥.𝑥,𝑡)=𝑡 by nested induction generalized over the variable type. Write the lambda case, including the calculation 𝗅𝗂𝖿𝗍(𝗂𝖽)=𝗂𝖽 on both constructors.
For the open term 𝑡:=𝗅𝖺𝗆(𝖺𝗉𝗉(𝗏𝖺𝗋(𝗓𝖾𝗋𝗈𝖵),𝗏𝖺𝗋(𝗌𝗎𝖼𝖵(𝑥)))), substituting 𝑥↦𝗏𝖺𝗋(𝑦) gives 𝗅𝖺𝗆(𝖺𝗉𝗉(𝗏𝖺𝗋(𝗓𝖾𝗋𝗈𝖵),𝗏𝖺𝗋(𝗌𝗎𝖼𝖵(𝑦)))). The old bound occurrence remains 𝗓𝖾𝗋𝗈𝖵; the free replacement is renamed by 𝗌𝗎𝖼𝖵. This is the observable capture-avoidance step.
Proof of Lemma 84.10 — Rename after lifted substitution
Proof. If 𝑧≡𝗓𝖾𝗋𝗈𝖵, both sides compute to 𝗏𝖺𝗋(𝗓𝖾𝗋𝗈𝖵). If 𝑧≡𝗌𝗎𝖼𝖵(𝑎), the left side is 𝗋𝖾𝗇𝖺𝗆𝖾(𝗅𝗂𝖿𝗍(𝑔),𝗋𝖾𝗇𝖺𝗆𝖾(𝗌𝗎𝖼𝖵,𝜎(𝑎))). By proposition 84.7, this equals renaming by 𝗅𝗂𝖿𝗍(𝑔)∘𝗌𝗎𝖼𝖵. On each 𝑏:𝐵, 𝗅𝗂𝖿𝗍(𝑔)(𝗌𝗎𝖼𝖵(𝑏))≡𝗌𝗎𝖼𝖵(𝑔(𝑏)). Applying renaming congruence gives the right side. ◻
Proof of Proposition 84.11 — Renaming–substitution fusion
Proof. Use nested induction generalized over 𝐴. The variable case is reflexivity. The application case uses the two induction hypotheses under 𝖺𝗉𝗉. In the lambda case, unfold both sides. The induction hypothesis at 𝖨𝗇𝖼𝗋(𝐴) reduces the goal to pointwise equality of the two lifted substitutions, which is lemma 84.10. Congruence for 𝗅𝖺𝗆 closes the case. ◻
Iteration returns a fixed type 𝐴. A proof about the input requires a result family. At a positive 𝐹 with an action, the dependent step must be told how an abstract recursive carrier embeds into the fixed point; only then can it state the indices of its induction hypotheses.
Let 𝐹 have an action, let 𝑃:𝜇𝖬𝐹→U𝑗, and assume the constructor 𝗂𝗇𝖬𝐹. For 𝑅:U𝑖 and 𝑒:𝑅→𝜇𝖬𝐹, put 𝖨𝖧(𝑅,𝑒):=∏𝑟:𝑅𝑃(𝑒(𝑟)),𝖦𝗈𝖺𝗅(𝑅,𝑒,𝑢):=𝑃(𝗂𝗇𝖬𝐹(𝗆𝖺𝗉𝐹(𝑒,𝑢))). A dependent Mendler algebra is 𝖲𝗍𝖾𝗉(𝑅):=∏𝑒:𝑅→𝜇𝖬𝐹𝖨𝖧(𝑅,𝑒)→∏𝑢:𝐹(𝑅)𝖦𝗈𝖺𝗅(𝑅,𝑒,𝑢),𝖣𝖬𝖠𝗅𝗀(𝐹,𝑃):=∏𝑅:U𝑖𝖲𝗍𝖾𝗉(𝑅).
The embedding 𝑒 records the fixed-point value denoted by each abstract component. Without 𝑒, the motive 𝑃 cannot be stated at an abstract recursive argument.
Assume the ordinary induction principle for the selected positive fixed point. Every 𝜓:𝖣𝖬𝖠𝗅𝗀(𝐹,𝑃) determines 𝗆𝗂𝗇𝖽𝐹(𝜓):∏𝑥:𝜇𝖬𝐹𝑃(𝑥) with constructor equation 𝗆𝗂𝗇𝖽𝐹(𝜓)(𝗂𝗇𝖬𝐹(𝑢))=𝜓(𝜇𝖬𝐹,𝗂𝖽,𝗆𝗂𝗇𝖽𝐹(𝜓),𝑢).
Proof of Proposition 84.13 — Dependent Mendler induction
Proof. Use ordinary fixed-point induction with motive 𝑃. At a layer 𝑢:𝐹(𝜇𝖬𝐹), the induction hypotheses have type 𝑃(𝑟) at every recursive component 𝑟. Instantiate 𝜓 with 𝑅:=𝜇𝖬𝐹 and 𝑒:=𝗂𝖽. Then 𝗆𝖺𝗉𝐹(𝑒,𝑢)=𝑢 by the identity action law, so the result has type 𝑃(𝗂𝗇𝖬𝐹(𝑢)). The ordinary computation equation gives the displayed equality. ◻
The construction proves no induction principle for a negative 𝐹, because its proof uses 𝗆𝖺𝗉𝐹 and the ordinary positive fixed-point induction principle. Dependent Mendler encodings that recover induction use additional identity-mapping or cast structure; their exact support is a separate signature, not an automatic consequence of definition 84.2.
Mixed variance and the hierarchy boundary
The operator 𝐹𝖥𝗈𝗈(𝑅):=𝟏+((𝑅→𝑅)×𝑅) has both a negative and a positive occurrence of 𝑅. It has no ordinary covariant action. A Mendler algebra can nevertheless consume one layer: 𝜙𝗅𝖾𝗇(𝑅,rec,𝗂𝗇𝗅⋆):=𝟢,𝜙𝗅𝖾𝗇(𝑅,rec,𝗂𝗇𝗋(𝑓,𝑟)):=𝗌𝗎𝖼(rec(𝑓(𝑟))). The embedded function 𝑓:𝑅→𝑅 may transform the child 𝑟:𝑅, and the recursive call may consume the result. It cannot receive a larger fixed-point value containing 𝑓, because its domain is the abstract type 𝑅.
This example marks the exact strength of the catamorphism. A Mendler histomorphism additionally exposes an unrolling function for recursive components. At the same negative operator, that extra observation permits an embedded function to be applied to a value that contains the function itself. Ahn and Sheard give the concrete 𝖥𝗈𝗈 value and 𝗅𝗈𝗈𝗉𝖥𝗈𝗈 reduction in their Figure 13 [AS11].
At the rank-zero calculus of Ahn and Sheard, programs defined by their 𝗆𝖼𝖺𝗍𝖺0 satisfy the stated termination argument, including the displayed 𝐹𝖥𝗈𝗈 example. Their 𝗆𝗁𝗂𝗌𝗍𝗈0 is not total for arbitrary negative base operators: 𝗅𝗈𝗈𝗉𝖥𝗈𝗈 applied to their value 𝖿𝗈𝗈 has an infinite reduction.
Proof of Theorem 84.14 — Hierarchy boundary, imported
Imported proof. Consequently “Mendler style” is not a termination theorem for the entire hierarchy. Iterator, primitive-recursive, destructor, course-of-value, and histomorphism interfaces must be checked separately. The terminating catamorphism instance and the divergent histomorphism trace are the rank-zero results surrounding Figure 13 on printed p. 242 of [AS11]. ◻
★★☆ Type every component of 𝜙𝗅𝖾𝗇 at an abstract 𝑅. Show that 𝑓(𝑟):𝑅 is a legal recursive argument. Then explain why an unrolled parent of type 𝜇𝖬𝐹𝖥𝗈𝗈 is not a legal argument to the same recursive call.
The abstraction argument above controls one recursion scheme. Mendler’s earlier second-order calculus gives a different theorem: strong normalization for an equational recursive-type constraint set satisfying a syntactic positivity condition.
Let 𝐼 be a finite set of recursive type atoms 𝜏𝑖, and let the finite constraint set contain equations 𝜏𝑖=𝑇𝑖. Generate type equality by these equations, symmetry, transitivity, and congruence for the arrow type. Property 𝑃 holds when forevery𝐶with𝜏𝑖=𝐶,everyoccurrenceof𝜏𝑖in𝐶ispositive. Arrow domains reverse polarity and arrow codomains preserve it.
The positive constraint 𝜏=𝐴→𝜏 passes the direct polarity check: the recursive atom occurs in the codomain. Change only the direction of the final arrow: 𝜏=𝜏→𝐴. Now 𝜏 occurs negatively in a type equal to itself, so property 𝑃 fails. The failure has an operational witness. Put 𝛿:=𝜆𝑥:𝜏.𝑥𝑥. Conversion by 𝜏=𝜏→𝐴 gives both 𝑥:𝜏→𝐴 and 𝛿:𝜏, hence 𝛿𝛿⟶𝛿𝛿. This is an explicit reducing cycle, so the changed calculus is divergent; we are not merely observing that a theorem no longer applies.
For Mendler’s finite second-order lambda calculus with the displayed equational type constraints, property 𝑃 implies strong normalization of every well-typed term. Property 𝑃 is equivalent to the source’s finite partition criterion of positive and negative classes.
Proof of Theorem 84.16 — Constraint normalization, imported
Imported proof. The reducibility proof orders only the finitely many constraint classes that occur in a typing derivation, splits each class into positive and negative components, and interprets arrow domains contravariantly. Proposition 10 states the partition criterion, and the following subsection performs the strong-normalization construction [Men91]. The theorem does not range over dependent types, arbitrary type-level computation, or the later Mendler-combinator hierarchy. ◻
★★☆ For constraints 𝜏0=𝐴→𝜏1,𝜏1=𝐵→𝜏0, calculate the polarity of every occurrence around the cycle and test property 𝑃. Then move 𝜏0 into the domain of the second equation and repeat the test.
The rank-polymorphic iteration and generalized higher-kinded schemes follow Abel, Matthes, and Uustalu [AMU05]. The nested de Bruijn representation, generalized fold, and fusion route follow Bird and Paterson [BP99]. The negative-datatype and histomorphism boundary follows Ahn and Sheard [AS11]. Property 𝑃 and its reducibility boundary are reconstructed from Mendler’s original constraint calculus [Men91].
★★☆ Define Mendler algebras for list sum and list append. Expand their equations at nil and cons. For append, state which list is represented by the result type and why no destructor for the first list is required.
★★★ Prove substitution composition for the nested terms: 𝗌𝗎𝖻𝗌𝗍(𝜏,𝗌𝗎𝖻𝗌𝗍(𝜎,𝑡))=𝗌𝗎𝖻𝗌𝗍(𝜆𝑎.𝗌𝗎𝖻𝗌𝗍(𝜏,𝜎(𝑎)),𝑡). Strengthen the induction over the variable type and prove the lifted- substitution equation needed by the lambda case before using it.
★★★ Reconstruct the typing failure of the attempted negative destructor and the typing success of 𝜙𝗅𝖾𝗇. Then transcribe the source’s 𝗅𝗈𝗈𝗉𝖥𝗈𝗈𝖿𝗈𝗈 example and display two repeated stages of its reduction. Keep the catamorphism and histomorphism signatures distinct.
★★★Practical project.mendler-nested-terms Implement in Kappa the nested variable constructors, lambda terms, lifting, renaming, and capture-free substitution of definition 84.8, definition 84.9. Maintain the invariant that entering a lambda maps the bound variable to zeroV and shifts every substituted free variable exactly once. On the named open term 𝜆.𝖺𝗉𝗉(𝗓𝖾𝗋𝗈𝖵,𝗌𝗎𝖼𝖵(0)), substitute the free variable 0 by free variable 7 and print 𝜆.𝖺𝗉𝗉(𝗓𝖾𝗋𝗈𝖵,𝗌𝗎𝖼𝖵(7)). Check renaming identity and the named two-step fusion instance. Reject a mutation that does not shift the substituted free variable with the witness capture-detected. The acceptance test requires the exact normal form, both laws, the rejection witness, and audit result [].