Lectures onType Theory
Chapter 79
Chapter 79Core route

Dependent Records and Primitive Projections

A nested Σ-type stores dependent components, but the terms pr1(pr1(r)) and pr2(r) do not say which components they select. Reordering two independent components also changes those terms. A true-record calculus makes field labels part of the syntax. That convenience comes with precise design choices: which occurrence of a repeated label is visible, how a field is removed while searching, and whether a record is judgmentally equal to the record of its projections.

Pollack’s left-associating true records

We freeze Pollack’s 2002 left-associating rules. If L is a record signature and A is a type family over records l:L, then L,r:A appends a visible field r. A value l,r=a stores a prefix l:L and a last component a:A(l). Labels do not bind in terms, and later occurrences shadow earlier ones.

Definition 79.1 — True-record rules

Formation and construction are

ΓL typeΓ,l:LA type
ΓL,r:A type
Rec-form
ΓL,r:A typeΓl:LΓa:A[l/x]
Γl,r=a:L,r:A
Rec-intro

The selected field is found from right to left. Restriction l|r removes the visible r field, and projection l.r returns its value:

Γl:L,r:A
Γl|r:L
Rec-rest
Γl:L,r:A
Γl.r:A[l|r/x]
Rec-proj

When the top label is different, both operations pass through it:

Γl:L,r:AΓ(l|r)|p:Prp
Γl|p:P
Rec-rest-pass
Γl:L,r:AΓ(l|r).p:Prp
Γl.p:P
Rec-proj-pass

The passing rules are read with the recursively established type of the searched-for field; the displayed P is that field type. They are a derivation schema for right-to-left lookup, not a width-subtyping judgment.

Computation is generated by l,r=a|rl,l,r=a.ra,l|p(l|r)|p(rp),l.p(l|r).p(rp). Congruence, conversion, symmetry, and transitivity are inherited from the ambient judgmental equality.

The rule names Rec-form and Rec-intro are local to this dependent true-record calculus. They are not the simply typed record rules tabulated earlier in appendix A; the term formers and dependency premises distinguish the two signatures.

There is deliberately no record-eta equation (notarule)l?l|r,r=l.r. Pollack’s displayed true-record rules do not contain it. Coquand, Pollack, and Takeyama later use generalized eta-expansion inside normalization, but state explicitly that object equality contains neither surjective pairing nor record field permutation. Eta expansion as an algorithmic device must not be confused with judgmental record eta.

For a concrete dependency, start from 1 and form L0:=1,L1:=L0,Carrier:Ui,L2:=L1,point:Carrier,PointedLoopi:=L2,loop:IdCarrier(point,point). The notation in a later field type abbreviates the corresponding projections from the prefix variable. The closed value p:=,Carrier=N,point=0,loop=refl0:PointedLoopi calculates by right-to-left lookup: p.looprefl0,p.point(p|loop).point0,p.Carrier(p|loop).Carrier((p|loop)|point).CarrierN. The last two lines include passing steps. The loop field is checked only after the carrier and point fields have been substituted into its type.

Exercise 79.1

★☆☆ Give the full type of each projection of p. Then calculate p.point and p.Carrier with every restriction and passing step shown.

Exercise 79.2

★★☆ Replace p by a neutral q:PointedLoopi. State the types of q.point and q.loop, and explain why neither projection contracts. Then show that q|loop,loop=q.loop is well typed but is not judgmentally equal to q by the displayed rules.

Substitution and the Sigma comparison

The operation l|r is what keeps the dependency well typed during field search. Substitution therefore acts simultaneously on the prefix, the field family, and every recursively exposed restriction.

Lemma 79.2 — Record substitution

If Γ,x:A,ΘJ is a formation, typing, or equality judgment of the record calculus and Γu:A, then Γ,Θ[u/x]J[u/x] is derivable.

Proof of Lemma 79.2 — Record substitution

Proof. Induct on the derivation. Formation and construction use ordinary substitution for L and for the dependent field type A(l). In Rec-proj, the induction hypothesis gives l[u/x]:L[u/x],r:A[u/x]; applying Rec-rest first gives the substituted prefix and then Rec-proj gives l[u/x].r:A[u/x][(l[u/x]|r)/z]. Capture-avoiding substitution composition identifies this classifier with (A[l|r/z])[u/x]. For Rec-rest-pass, the induction hypothesis supplies the substituted outer record and the recursive premise ((l|r)|p)[u/x]:P[u/x]. Preserving rp reconstructs the conclusion (l|p)[u/x]:P[u/x]. For Rec-proj-pass, the recursive premise is ((l|r).p)[u/x]:P[u/x] and the reconstructed conclusion is (l.p)[u/x]:P[u/x]. For each of the four computation axioms, the induction hypotheses type the substituted operands and the same computation axiom, with all operands substituted, yields the required equality. A congruence case applies the induction hypothesis to every displayed premise and then rebuilds that same congruence rule; conversion uses the substituted type equality. These are all new cases. ◻

For pairwise fresh labels, flatten 1,1:A1,k:Ak as (1:A1,,k:Ak). Define a translation to prefix-nested Sigma types by S():=1,S(Δ,:A):=ρ:S(Δ)AS(ρ),l,=aS:=(lS,aS),(l|)S:=pr1(lS),(l.)S:=pr2(lS). Passing through a different top label first applies pr1 and continues recursively. Thus named selection becomes a finite projection spine.

Theorem 79.3 — The exact Sigma comparison

On the fresh-label fragment, the translation ()S preserves formation, typing, judgmental equality, restriction computation, and projection computation. Hence the selected true-record rules are conservative over the ambient negative Sigma and Unit rules for record-free conclusions. The theorem does not reflect arbitrary Sigma equality and does not add record eta.

Proof of Theorem 79.3 — The exact Sigma comparison

Proof. Induct on the record signature. At the last field, restriction beta translates to pr1(lS,aS)lS, and projection beta to pr2(lS,aS)aS. A passing computation translates to one outer first projection followed by the induction hypothesis. Formation and construction are Sigma formation and introduction. Congruence and conversion commute with the translation. Translating a derivation of a record-free conclusion leaves that conclusion unchanged, which proves conservativity. No converse eta step is used. ◻

Pollack compares left-associating records with labeled Sigma types at exactly this strength: restriction exposes the prefix and projection exposes the selected component. Repeated labels remain meaningful in his calculus, but the fresh-label fragment is the one used for the algorithmic correspondence below.

Exercise 79.3

★★☆ Translate the candidate eta equation q=?q|r,r=q.r to Sigma syntax. Show that Sigma eta would validate the translation, then explain why this does not make the source equation derivable: preservation is not reflection from all target equalities.

Exercise 79.4

★★☆ Let L=L,r:A. Construct λq.q|r:LL. Contrast this explicit operation with a candidate width rule assigning the same term q both types L and L. Explain why the selected calculus contains the function but not that rule.

The record-only CPT correspondence

Coquand, Pollack, and Takeyama use right-associating records. We isolate the fragment CPTrec containing the empty signature 1, signature extension :A,x.B, empty value (), value extension (=M,N), and primitive selection M.. Labels are fresh in a tail. Its two dot reductions are (=M,N).M,(=M,N).kN.k(k). We exclude singleton and manifest fields, structural subtyping, signature strengthening, modules, and type-family application.

For a fresh-label Pollack signature Δ=(1:A1,,k:Ak), define [[]]CPT:=1,[[1:A1,Δ]]CPT:=1:A1C,x.[[Δ]]CPT,[[{1=a1;;k=ak}]]CPT:=(1=a1C,((k=akC,()))),[[q.]]CPT:=qC.. Pollack restriction is used only by the source lookup derivation; a maximal projection q. translates directly to CPT dot selection. Call this the projection fragment: restriction is not exposed as a standalone result term. This boundary is necessary because CPT’s record object syntax has dot selection but no whole-tail projection.

Theorem 79.4 — Pollack-to-CPT correspondence

For the fresh-label projection fragment:

  1. ΓM:A in Pollack’s rules iff ΓCMC:AC in CPTrec;

  2. ΓM=N:A in Pollack’s beta theory iff the translated terms are equal by beta and dot conversion in CPTrec.

The equivalence is only for the displayed fragment and equality theory; it does not smuggle in subtyping or record eta.

Proof of Theorem 79.4 — Pollack-to-CPT correspondence

Proof. For preservation, induct on the Pollack derivation. Formation and construction reverse the left-associated prefix into a right-associated CPT tail. A source projection search through m later labels becomes exactly m applications of the second rule in (79.4), followed by the first. Dependency is preserved because both derivations substitute the same earlier field values before checking a later type.

For reflection, invert the CPT derivation on the image grammar. A translated signature has a unique right-associated field spine and translated terms have only image constructors. Reconstruct Pollack formation or construction one field at a time. A dot derivation determines a unique label position because labels are fresh; rebuild the corresponding finite restriction search. The same induction reflects a dot-conversion chain to (79.1)(79.3). No CPT subtyping or singleton rule occurs in the restricted derivation, so there is no remaining case. ◻

Theorem 79.5 — Checking and available canonicity for records

Assume the record-free base has the neutral eta-expansion normalizer of Coquand–Pollack–Takeyama, decidable type equality, and canonical forms for 1 and the field types in the empty context. Then, for the fresh-label projection fragment:

  1. formation, construction, projection typing, and judgmental equality are decidable;

  2. dot reduction preserves typing;

  3. a closed beta-normal inhabitant of a record signature is a nested record constructor whose fields have the corresponding base canonical forms.

The theorem asserts beta-normal canonicity, not judgmental record eta.

Proof of Theorem 79.5 — Checking and available canonicity for records

Proof. Use the correspondence theorem. The CPT normalizer extends neutral eta-expansion by the clauses printed with the record fragment; alpha-comparison of the resulting normal forms decides equality. Checking a constructor proceeds from the first field to the last, substituting each checked value into the remaining tail. Projection follows the unique finite label spine. Reflection transfers each successful or failed query back to the Pollack fragment.

For preservation, the selected dot redex (=M,N). has the field type assigned to M. In the different-label case the typing derivation for N.k is already a premise. The substitution lemma handles compatible reductions below dependent tails.

For canonicity, normalize the translated closed term. A closed neutral cannot be headed by a variable, and a dot-headed neutral would have a smaller closed neutral record scrutinee. Finite descent rules this out. Hence the normal form is () at the empty signature or (=M,N) at an extension. Induction on the signature and the assumed base canonical forms gives the claim; reflection returns the corresponding left-associated Pollack value. Generalized eta-expansion helps the equality algorithm compare neutrals, but is nowhere oriented as a source reduction or asserted as source equality. ◻

Suggested first pass.

Begin with exercise 79.5, then complete exercise 79.6.

Exercise 79.5

★★☆ Extend PointedLoopi by a Boolean name field. Give its left-associated Pollack signature, its right-associated CPT translation, and the complete dot-reduction trace for selecting the point and carrier fields. Mark the source restriction step corresponding to each target dot-pass step.

Exercise 79.6

★★★ Practical project.dependent-record-checker Implement in Kappa formation and checking for the fresh-label fragment of definition 79.1. Check fields from left to right and implement named projection by a right-to-left label search. Accept the displayed PointedLoopi value and compute its point projection to zero. Reject a record whose carrier is N, point is 0, and loop endpoints are both suc(0); name the expected and actual endpoint types. Also reject a duplicate-label declaration in this executable fragment. The acceptance test compares these exact results. This finite checker does not implement Pollack’s full repeated-label calculus or prove the correspondence theorem.

Sources and theorem boundary. The rules Rec-formRec-proj-pass and their four computations are the left-associating true-record rules in Pollack, pp. 6–7 [Pol02]; the record/Sigma comparison is bounded by his discussion on p. 7. His system has no record-eta rule. The CPTrec grammar, dot reductions, generalized eta-expansion policy, and normalization argument are isolated from Coquand, Pollack, and Takeyama, pp. 4–5 and 11–12 [CPT03]. The correspondence and the specialization of checking/canonicity are proved here because Pollack’s paper does not own them and the CPT development is substantially larger. Singleton fields, manifest fields, structural subtyping, module applications, signature strengthening, record permutation, and surjective pairing remain outside every theorem in this chapter.

Search the book

Type to search the local edition.