Coherence of Type Class Resolution
Pith reviewed 2026-05-25 11:25 UTC · model grok-4.3
The pith
Elaboration-based type class resolution remains coherent despite nondeterminism from superclasses and flexible contexts.
A machine-rendered reading of the paper's core claim, the machinery that carries it, and where it could break.
Core claim
The central claim is that elaboration-based type class resolution is coherent in the presence of nondeterminism such as superclasses and flexible contexts. The proof proceeds by nondeterministically elaborating source programs into an intermediate language that preserves contextual equivalence, shown via logical relations, and then deterministically elaborating the intermediate language into the target language, which preserves the equivalence property by construction.
What carries the argument
Two-step elaboration: nondeterministic step into an intermediate language that preserves contextual equivalence (via logical relations), followed by deterministic step into the target language.
If this is right
- Different resolution choices during compilation never change the observable behavior of the resulting program.
- Superclasses and flexible contexts can be added without breaking the guarantee that all valid resolutions are equivalent.
- Compilers are free to pick any resolution strategy as long as it produces a valid elaboration.
- The same coherence property holds for languages that use similar elaboration-based resolution such as Mercury and PureScript.
Where Pith is reading between the lines
- The two-step method could be reused to prove coherence in other elaboration systems that lose direct source-target correspondence.
- It suggests a general pattern for proving properties when direct full abstraction fails but an intermediate language can restore it.
- The approach may extend to features like overlapping instances if they can be modeled in the intermediate language.
Load-bearing premise
The assumption that contextual equivalence between different elaborations in the intermediate language corresponds exactly to equivalence observable from the source language.
What would settle it
A source-language program and context where two different valid resolutions produce target programs that can be distinguished by an observation possible in the source language.
Figures
read the original abstract
Elaboration-based type class resolution, as found in languages like Haskell, Mercury and PureScript, is generally nondeterministic: there can be multiple ways to satisfy a wanted constraint in terms of global instances and locally given constraints. Coherence is the key property that keeps this sane; it guarantees that, despite the nondeterminism, programs still behave predictably. Even though elaboration-based resolution is generally assumed coherent, as far as we know, there is no formal proof of this property in the presence of sources of nondeterminism, like superclasses and flexible contexts. This paper provides a formal proof to remedy the situation. The proof is non-trivial because the semantics elaborates resolution into a target language where different elaborations can be distinguished by contexts that do not have a source language counterpart. Inspired by the notion of full abstraction, we present a two-step strategy that first elaborates nondeterministically into an intermediate language that preserves contextual equivalence, and then deterministically elaborates from there into the target language. We use an approach based on logical relations to establish contextual equivalence and thus coherence for the first step of elaboration, while the second step's determinism straightforwardly preserves this coherence property.
Editorial analysis
A structured set of objections, weighed in public.
Referee Report
Summary. The paper claims to deliver the first formal proof of coherence for elaboration-based type class resolution in the presence of nondeterminism arising from superclasses and flexible contexts. The proof proceeds in two steps: nondeterministic elaboration into an intermediate language (IL) whose contextual equivalence is established via logical relations, followed by deterministic elaboration from the IL into the target language, which preserves the equivalence.
Significance. If the proof is correct, the result is significant: it supplies a machine-checked or at least rigorously formalized argument for a property long assumed in Haskell, Mercury and PureScript but previously lacking a published proof under realistic sources of nondeterminism. The two-step strategy directly tackles the full-abstraction-style problem that target-language contexts can distinguish elaborations invisible at the source level.
minor comments (3)
- §3, definition of the IL: the typing rules for dictionary construction are presented only informally; a compact inference-rule figure would make the subsequent logical-relation definition easier to follow.
- §4.2, Lemma 4.3 (fundamental lemma): the statement mentions 'closed terms' but the accompanying proof sketch quantifies over open terms with a closing substitution; clarifying the exact statement would remove a minor source of confusion.
- Figure 5 (example derivation): the source and target terms are aligned vertically but the intermediate-language term is omitted; adding the IL term would illustrate the two-step path more clearly.
Simulated Author's Rebuttal
We thank the referee for their positive assessment of the paper, recognition of its significance, and recommendation for minor revision. No specific major comments were provided in the report.
Circularity Check
No significant circularity identified
full rationale
The paper's central result is a formal proof of coherence via a two-step elaboration strategy: nondeterministic elaboration into an intermediate language whose contextual equivalence is established using standard logical relations, followed by a deterministic step that preserves the property. This technique is externally motivated by full-abstraction arguments and does not reduce to any self-definition, fitted parameter renamed as prediction, or load-bearing self-citation chain. The derivation is self-contained against the stated semantics and does not invoke uniqueness theorems or ansatzes from prior author work as the sole justification.
Axiom & Free-Parameter Ledger
axioms (1)
- domain assumption Contextual equivalence is preserved by the first elaboration step
Reference graph
Works this paper leans on
-
[1]
By iEval-app: e ′ = e ′ 1 e2 iTm-constrI Σ; ΓC ; Γ,δ: Q ⊢tm e :σ ΓC ; Γ ⊢Q Q Σ; ΓC ; Γ ⊢tm λδ: Q.e : Q ⇒σ iTm-constrI with ΓC = •, Γ = •. λδ: Q.e is a value. iTm-constrE Σ; ΓC ; Γ ⊢tm e : Q ⇒σ Σ; ΓC ; Γ ⊢d d : Q Σ; ΓC ; Γ ⊢tm e d :σ iTm-constrE with ΓC = •, Γ = •. From the 1st rule premise: Σ; ΓC ; Γ ⊢tm e : Q ⇒σ (110) By applying the induction hypothesis...
work page 2019
-
[2]
∈ ϕand for every mappingδ7→ (dv ′ 1, dv ′
-
[3]
Therefore, we obtainγi(ϕi(R(Λa.ei))) = Λa.γi(ϕi(R(ei))), for i ∈ { 1, 2}
∈ γ, we have a < fv(e ′ i ) and a < fv(dv ′ i ), where i ∈ { 1, 2}. Therefore, we obtainγi(ϕi(R(Λa.ei))) = Λa.γi(ϕi(R(ei))), for i ∈ { 1, 2}. With these equations, the goal above reduces to (Σ1 : Λa.γ1(ϕ1(R(e1))), Σ2 : Λa.γ2(ϕ2(R(e2)))) ∈ E ⟦∀a.σ⟧ΓC R By applying the definition of the E relation, taking into account that expressions of the form Λa.e are v...
work page 2019
-
[4]
⇝ M ′ 2 (662) P; ΓC ; Γ′ ⊢M tm e ′ 1 ⇒τ1 →τ2 ⇝ e11 (663) P; ΓC ; Γ′ ⊢M tm e ′ 1 ⇒τ′ 1 →τ2 ⇝ e12 (664) By Lemma 7, we know thatτ′ 1 =τ1. By applying Part 2 of this theorem to Equations 661 and 662, we get: Σ1 : M ′ 1 ≃l oдΣ2 : M ′ 2 : (ΓC ; Γ ⇒σ) 7→ ( ΓC ; Γ′ ⇒σ1) By unfolding the definition of logical equivalence in the above and applying it on Equation 6...
work page 2019
-
[5]
Consequently, since F D context elaboration is deterministic (Theorem 38), we get that M 1 = M ′ 1 and M 2 = M ′
-
[6]
□ M.3 Partial Coherence Theorems Theorem 27 (Coherence - Dictionaries - Part A)
Goal 745 follows from Equations 746, 748, 750 and 751. □ M.3 Partial Coherence Theorems Theorem 27 (Coherence - Dictionaries - Part A). If P; ΓC ; Γ ⊨M Q ⇝ d 1 and P; ΓC ; Γ ⊨M Q ⇝ d 2 and ⊢M ct x P; ΓC ; Γ ⇝ Σ1; ΓC ; Γ and ⊢M ct x P; ΓC ; Γ ⇝ Σ2; ΓC ; Γ then ΓC ; Γ ⊢ Σ1 : d 1 ≃l oдΣ2 : d 2 : Q where ΓC ; Γ ⊢M Q Q ⇝ Q. Proc. ACM Program. Lang., Vol. 3, No...
work page 2019
-
[7]
∈ γwhere (Σ1 : dv ′ 1, Σ2 : dv ′
-
[8]
From Theorem 25, we get that ΓC ⊢ Σ1 ≃l oдΣ2
∈ V ⟦Q⟧ΓC R (784) We thus know that: γ1(ϕ1(R(δ))) = dv1 γ2(ϕ2(R(δ′))) = dv ′ 2 From the definition of the V relation in Equations 783 and 784 it follows that: Σ1; ΓC ; • ⊢d dv1 : R(Q) (785) Σ2; ΓC ; • ⊢d dv ′ 2 : R(Q) (786) Applying preservation Theorem 7 to our hypothesis that ⊢M ct x P; ΓC ; Γ ⇝ Σ1; ΓC ; Γ and ⊢M ct x P; ΓC ; Γ ⇝ Σ2; ΓC ; Γ gives us ⊢ct...
-
[9]
□ Theorem 28 (Coherence - Expressions - Part A)
∈ V ⟦R(Q)⟧ΓC • (787) Goal 782 follows from Equation 787 by Lemma 35. □ Theorem 28 (Coherence - Expressions - Part A). • If P; ΓC ; Γ ⊢M tm e ⇒τ⇝ e1 and P; ΓC ; Γ ⊢M tm e ⇒τ⇝ e2 and ⊢M ct x P; ΓC ; Γ ⇝ Σ1; ΓC ; Γ and ⊢M ct x P; ΓC ; Γ ⇝ Σ2; ΓC ; Γ then ΓC ; Γ ⊢ Σ1 : e1 ≃l oдΣ2 : e2 :σwhere ΓC ; Γ ⊢M ty τ⇝σ. • If P; ΓC ; Γ ⊢M tm e ⇐τ⇝ e1 and P; ΓC ; Γ ⊢M tm...
work page 2019
-
[10]
From Theorem 3, in combination with Equations 854 and 855, we know that: ⊢ct x P; ΓC , ΓC ′ 1; • ⇝ • ⊢ct x P; ΓC , ΓC ′ 2; • ⇝ • The goal follows from the induction hypothesis. pдm = inst ; pдm′ By case analysis on the program typing derivations (sPgmT-inst): P; ΓC ⊢inst inst : P 11 (856) P; ΓC ⊢inst inst : P 21 (857) P, P 11; ΓC ⊢pдm pдm′ :τ; P 12; ΓC 1 ...
work page 2019
-
[11]
We do this by showing that e0 − →∗ e ′ 0
We need to show that there exists aneh such that e0 − →∗ eh and e ′ 0 − →∗ eh. We do this by showing that e0 − →∗ e ′ 0. By inversion, the last part of Derivation 1007 must be an instance of iTm-arrI directly followed by iTm-arrE, as shown below. Σ; ΓC ; •, x :σ⊢tm e1 :σ′ ⇝ e1 ΓC ; • ⊢ty σ⇝σ Σ; ΓC ; • ⊢tm λx :σ.e1 :σ→σ′ ⇝λx :σ.e1 iTm-arrI Σ; ΓC ; • ⊢tm e2...
work page 2019
-
[12]
We do this by showing that e0 − →∗ e ′ 0
We need to show that there exists aneh such that e0 − →∗ eh and e ′ 0 − →∗ eh. We do this by showing that e0 − →∗ e ′ 0. By inversion, the last part of Derivation 1011 must be an instance of iTm-forallI directly followed by iTm-forallE, as shown below. Σ; ΓC ; •, a ⊢tm e :σ′ ⇝ e Σ; ΓC ; • ⊢tm Λa.e : ∀a.σ′ ⇝ Λa.e iTm-forallI ΓC ; • ⊢ty σ⇝σ Σ; ΓC ; • ⊢tm (Λ...
work page 2019
-
[13]
We do this by showing that e0 − →∗ e ′ 0
We need to show that there exists aneh such that e0 − →∗ eh and e ′ 0 − →∗ eh. We do this by showing that e0 − →∗ e ′ 0. By inversion, the last part of Derivation 1015 must be an instance of iTm-constrI directly followed by iTm-constrE, as shown below. Σ; ΓC ; •,δ: Q ⊢tm e :σ⇝ e1 ΓC ; • ⊢ty σ⇝σ Σ; ΓC ; • ⊢tm λδ: Q.e : Q ⇒σ⇝λδ:σ.e1 iTm-constrI Σ; ΓC ; • ⊢d...
-
[14]
We need to show that there is a eh such that e0 − →∗ eh and e ′ 0 − →∗ eh. Proc. ACM Program. Lang., Vol. 3, No. ICFP, Article 91. Publication date: August 2019. 91:142 Gert-Jan Bottu, Ningning Xie, Koar Marntirosian, and Tom Schrijvers By inversion on Equation 1017, we have e0 = ((Λaj.λδi :σ′ i i .{m = em})σj ei).m andσ0 = [[σj/aj]σq/a]σm, for someσm, em...
work page 2019
-
[15]
We do this by showing that e0 − →∗ e ′ 0
We need to show that there exists aneh such that e0 − →∗ eh and e ′ 0 − →∗ eh. We do this by showing that e0 − →∗ e ′ 0. By inversion, the last rule used for Derivation 1020 must be an instance of iTm-let. Σ; ΓC ; • ⊢tm e1 :σ⇝ e1 Σ; ΓC ; •, x :σ⊢tm e2 :σ′ ⇝ e2 ΓC ; • ⊢ty σ⇝σ Σ; ΓC ; • ⊢tm let x :σ= e1 in e :σ′ ⇝ let x :σ= e1 in e2 iTm-constrI where e0 = l...
work page 2019
discussion (0)
Sign in with ORCID, Apple, or X to comment. Anyone can read and Pith papers without signing in.