Lectures onType Theory
Qualified types and dictionary evidence
appendix sectionrules

Qualified types and dictionary evidence

For QTC0, τ::=αIntBoolStringListτττ,p::=Kτ,σ::=α¯.Pτ. The finite superclass graph is acyclic. Each primitive instance head begins with a constructor. Every premise is headed by a proper subterm of the result head. Resolution uses the finite effective table I: for each primitive clause and each reachable superclass it contains the clause obtained by following the fixed shortest superclass path. Its builder is the primitive constructor followed by that path’s dictionary projection. For each requested class, all effective result heads must be pairwise nonunifiable. This check is performed after closure, so a direct EqInt clause is rejected when it would overlap the projection derived from OrdInt. An evidence context has distinct canonical keys. The fixed partial selector bestΔ chooses exact local evidence first. Otherwise it chooses the uniquely ordered shortest superclass projection. Resolution consists of exactly

bestΔ(Kτ)=d
resolveC,Δ(Kτ)=d
E-Local
bestΔ(Kτ)pickC(Kτ)=(P,b)resolveC,Δ(p)=dp (pP)
resolveC,Δ(Kτ)=bd¯p
E-Instance

The partial function pick freshens and one-way-matches the unique effective candidate; it is not symmetric unification.

Normalization nfC uses one fixed-priority agenda. It processes exact or projected local evidence before instances; allocates a fresh hole only for an unresolved variable-headed request; and expands an unresolved constructor request through its unique one-way-matching instance. Completed constructor frames install their evidence for later agenda requests. Duplicate goals share the first recorded evidence, and a retained subclass hole discharges its superclass holes. A missing constructor-headed instance rejects immediately. Its total result is reject(p)orok(Q,η), where Q is the ordered irredundant variable-headed hole set and η reconstructs every input request jointly from those holes. The open sets P and Q have the same solvable ground instances. More exactly, if normalization returns ok(Q,η), then for every substitution S, normalizing SP and SQ rejects together or returns the same canonical set with commuting evidence templates. If canonical R entails SP, then it entails SQ; this is the factorization direction used by principality. A source judgment is formed only with canonical P and canonical, unambiguous schemes in Γ. Its four rules are

x:σΓσ(Qτ)C;PQ
C;P;Γx:τ
Q-Var
C;P;Γ,x:τ1e:τ2
C;P;Γλx.e:τ1τ2
Q-Lam
C;P1;Γe1:τ1τ2C;P2;Γe2:τ1nfC(P1P2)=ok(P,η)
C;P;Γe1e2:τ2
Q-App
C;P1;Γe1:τ1GenC(Γ;P1;τ1)=(Pr,σ,ζ)C;P2;Γ,x:σe2:τ2nfC(PrP2)=ok(P,η)
C;P;Γlet x=e1 in e2:τ2
Q-Let

Here generalization quantifies exactly the variables of the normalized predicates and result type that are not fixed by Γ, retains the other canonical predicates as Pr, records the template ζ, and requires ftv(Q)ftv(τ1). Type substitution acts on an environment through the partial canonical action SΓ: it freshens bound variables, substitutes only free variables, renormalizes each predicate interface, and records the induced evidence transport. Substitution naturality of normalization gives TSΓ=TSΓ up to fresh binders whenever both sides are defined, with alpha-equivalent composite evidence transports.

Qualified inference returns WC(Γ,e)=(P,S,τ). Writing cnfC(P)=Q for the successful canonical predicate component, its four clauses are:

  1. a fresh instance (Q,τ) of Γ(x) returns (cnfC(Q),id,τ);

  2. an abstraction chooses fresh a, recursively obtains (P,S,τ) in Γ,x:a, and returns (P,S,S(a)τ);

  3. an application obtains (P1,S1,τ1), then (P2,S2,τ2) in S1Γ, sets U=mgu(S2τ1,τ2a), and returns (cnfC(U(S2P1P2)),US2S1,U(a));

  4. a let obtains (P1,S1,τ1), generalizes it in S1Γ to (Pr,σ,ζ), then obtains (P2,S2,τ2) in S1Γ,x:σ, and returns (cnfC(S2PrP2),S2S1,τ2).

Every failed normalization or ambiguity check rejects at its displayed clause; evidence templates are uniquely recomputed from the recorded W derivation rather than hidden in a fourth return component.

The evidence-explicit target core adds type and dictionary abstraction and application: u::=xλx:T.uu1u2let x=u1 in u2Λα.uu[T]λ{d:D}.uu{δ}ciπK,Ku. The dictionary forms are typed by

Γ,d:Du:T
Γλ{d:D}.u:DT
U-DictLam
Γu:DTΓδ:D
Γu{δ}:T
U-DictApp

Superclass edges and instances contribute πK,K:α.KD(α)KD(α),ci:α¯.(p1)D(pm)DKD(Cτ¯). For canonical P, let ΔP=dp:pD in canonical order. An evidence template η acts by hole replacement ηu, and a type substitution acts on core syntax and templates by Su. Elaboration is indexed by the successful W derivation W. Its complete family is

x:(α¯.Qτ0;κx)ΓresolveC,ΔP(θq)=δq (qQ)
C;ΔP;ΓDWx:θτ0x[θα¯]{(θκx)(δ¯q)}
D-Var
a freshWC(Γ,x:a,e)=(P,S,τ)C;ΔP;Γ,x:aDW0e:τu
C;ΔP;ΓDWλx.e:S(a)τλx:|S(a)|.u
D-Lam
WC(Γ,e1)=(P1,S1,τ1)C;ΔP1;ΓDW1e1:τ1u1WC(S1Γ,e2)=(P2,S2,τ2)C;ΔP2;S1ΓDW2e2:τ2u2U=mgu(S2τ1,τ2a)nfC(U(S2P1P2))=ok(P,η)
C;ΔP;ΓDWe1e2:U(a)(η|U(S2P1)US2u1)(η|U(P2)Uu2)
D-App

For let, if ζ:ΔPr,ΔQeΔP1 is the generalization template and η:ΔPeΔS2Pr,ΔP2, write ηr,η2 for its restrictions and define ulet:=let x=Λa¯.λ{d¯Q:|Q|}.((ηridQ)S2ζ)S2u1 in η2u2.

WC(Γ,e1)=(P1,S1,τ1)C;ΔP1;ΓDW1e1:τ1u1GenC(S1Γ;P1;τ1)=(Pr,a¯.Qτ1,ζ)WC(S1Γ,x:a¯.Qτ1,e2)=(P2,S2,τ2)C;ΔP2;S1Γ,x:a¯.Qτ1DW2e2:τ2u2nfC(S2PrP2)=ok(P,η)
C;ΔP;ΓDWlet x=e1 in e2:τ2ulet
D-Let

The target environment is |SΓ|, where S is the substitution returned by W. The exact top-level closure is closeC(e)=Λa¯.λ{d¯Q:|Q|}.ζu when W at the empty environment succeeds, generalization returns no residual predicates, and u is the displayed W-indexed elaboration. Missing ground evidence or ambiguity rejects closure. The evidence-core roots are ordinary, type, dictionary, and let beta under call-by-value compatible closure. Brace erasure has forward step simulation and existential reverse lifting; it is not injective.

For the explicitly typed ground compatibility exercises, retain the annotated forms s::=eq[A](s1,s2)(KAs)sK,A. They specialize the preceding QTC0 elaboration rather than forming a second inference calculus. A finite ground table Σ and a local evidence map Ψ each contain at most one entry per normalized class/type key, and resolveΨ,Σ tries the local map before the table. The three annotated rules are

resolveΨ,Σ(Eq,A)=dΨ;Σsiei (i=1,2)
Ψ;Σeq[A](s1,s2)de1e2
ED-Method
d freshΨ[(K,A)d];Σse
Ψ;Σ(KAs)λd:KD(A).e
ED-Bind
Ψ;ΣseresolveΨ,Σ(K,A)=d
Ψ;ΣsK,Aed
ED-Discharge

The bounded associated-type extension ATS0 adds saturated synonym applications and equality constraints: η::=Sτ¯,π::=Kτη=τ,θ::=α¯.PKτα¯.η=τ. Entailment Θπ includes class specialization and modus ponens together with reflexivity, symmetry, transitivity, and congruence for equality. The distinctive rules and algorithmic judgment are ΘCollectsτΘElemτ typeATWFΘΓe:τ1Θτ1=τ2ΘΓe:τ2ATConv, Θ,UTΓWe:τ. The last judgment returns class constraints, pending equality constraints, a substitution, and a monotype. Its imported soundness endpoint is theorem 13.23; no completeness or principality result is attached to this extension. Its exact admission conditions also require specific nonoverlapping constructor-headed instances, decreasing contexts, saturated synonym applications, the designated variable-headed form for programmer equality constraints, and the two fixed-variable checks stated in section 13.4. The source paper omits its evidence rules; the displayed dictionary/type-passing instance in the chapter is the book’s local target sketch.

The separately imported COCHIS comparison uses predicative types, monotypes, terms, and contexts ρ::=αρ1ρ2α.ρρ1ρ2,σ::=ασ1σ2,e::=xλ(x:ρ).ee1e2Λα.eeσ?ρλ?ρ.ee1 with e2,Δ::=Δ,x:ρΔ,αΔ,?ρ:x. Only monotypes instantiate . Its resolution judgments are ΔrρE,A;Δf[ρ]E,A;Δ;[Δ]lτE,Δ;[ρ];xmρ¯;z¯;τE,stable(A;Δ;ρ;x;τ). The load-bearing recursive rules are

tyvars(Δ);Δf[ρ]E
ΔrρE
C-R-Main
A;Δ,?ρ1:zf[ρ2]Ez fresh
A;Δf[ρ1ρ2]λz:|ρ1|.E
C-R-IAbs
A;Δ;[Δ]lτE
A;Δf[τ]E
C-R-Simp
Δ;[ρ];xmρ¯;z¯;τEA;Δf[ρ¯]E¯
A;Δ;[Δ,?ρ:x]lτE[E¯/z¯]
C-L-Match
stable(A;Δ;ρ;x;τ)A;Δ;[Δ]lτE
A;Δ;[Δ,?ρ:x]lτE
C-L-NoMatch
Δ;[τ];xm;;τx
C-M-Simp
Δ,?ρ1:z;[ρ2];xzmρ¯;z¯;τEz fresh
Δ;[ρ1ρ2];xmρ1,ρ¯;z,z¯;τE
C-M-IApp
ΔσΔ;[ρ[σ/α]];x[σ]mρ¯;z¯;τE
Δ;[α.ρ];xmρ¯;z¯;τE
C-M-TApp

Quantifier matching instantiates [α.ρ];x to [ρ[σ/α]];x[σ] when Δσ, then continues matching. The unambiguity predicate is UA(A;τ)iffAftv(τ),UA(A;α.ρ)iffUA(A{α};ρ),UA(A;ρ1ρ2)iffUA(A;ρ1) and UA(A;ρ2). The valid-substitution judgment valid(A;Δ;θ) extends by the singleton substitution [σ/α] only when αA, Δ=Δ0,α,Δ1, σ is well scoped in Δ0, and the remainder is valid in (Δ0,Δ1)[σ/α]. Finally, stable(A;Δ;ρ;x;τ) excludes every such valid substitution under which the skipped ρ would match τ. This card reproduces the comparison’s recursive evidence plumbing; the complete systems and remaining premises are source-cited to Figs. 2 and 6–10 in the chapter.

Search the book

Type to search the local edition.