Lectures onType Theory
Chapter 132
Chapter 132Optional

Systems D and DC: A Dependent Haskell Core Specification

Prerequisites. Direct starred prerequisites: Chapter 131. The dependent function and equality rules of chapter 26 supply the remaining prerequisites. No later core chapter depends on this route.

Consider the vector zip whose two arguments are known to have the same length: zip:Πn:NatΠa:Πb:Vec anVec bnVec (a,b)n. Three of its five arguments are marked Π: the length n and the two element types are to be erased before the program runs. In chapter 131 that decision was made by a syntactic class — types and coercions were erased, terms were kept. Here n is a natural number, an ordinary run-time value of an ordinary type, and yet it must be erased. The class “type” has stopped coinciding with the class “erasable”.

Nor can erasability be read off the type. The body of zip matches on a vector whose constructor carries an equality constraint, and the branch for the empty vector must produce a value at type Vec (a,b)n using the assumption n=0. Reusing the mechanism of chapter 131, that assumption is a coercion, and the coercion must also be erased. So a single calculus must classify three different things — what is computed, what is erased, and what is proved — and it must do so while allowing types to contain arbitrary, possibly divergent, terms.

This chapter freezes Systems D and DC of Weirich, Voizard, Azevedo de Amorim and Eisenberg (2017), whose syntax, judgments, typing rules, definitional equality and prop equality are that paper’s Figures 1–9. D is the implicit language: it has no annotations and an undecidable type system, and it is where the soundness argument lives. DC is the annotated language: its type checking is decidable and its types are unique, and it is connected to D by an erasure that forgets exactly the annotations.

System D

Definition 132.1 — Syntax of D

ρ::=+relevance,a,b,A,B::=xFλρx.aabρΠρx:ABΛc.aa[]c:ϕ.A,ϕ::=aAbpropositions,v::=λ+x.aλx.vΛc.aΠρx:ABc:ϕ.A,Γ::=Γ,x:AΓ,c:ϕ,Δ::=Δ,cavailable set,Σ::=Σ{Fa:A}signature. One sort classifies every type, and :. Terms and types share this syntax. Write AB for Π+x:AB when x does not occur free in B, and ϕA for c:ϕ.A when c does not occur free in A.

Three binders must be distinguished at once. λ+ abstracts a value the body may use; λ abstracts a value the body may not use, and whose argument is therefore written at the application site; Λc abstracts a proof of an equality proposition, discharged by the token . The three eliminations are ab+, a and a[].

Definition 132.2 — Reduction

Primitive reduction a0b and one-step reduction ab are generated by

(λρx.v)aρ0v[a/x]
E-AppAbs
(Λc.b)[]0b[/c]
E-CAppCAbs
Fa:AΣ0
F0a
E-Axiom
a0a
aa
E-Prim
aa
λx.aλx.a
E-AbsTerm
aa
abρabρ
E-AppLeft
aa
a[]a[]
E-CAppLeft

Reduction is call by name and deterministic. The one rule that is not standard is E-AbsTerm, which reduces under an irrelevant abstraction; correspondingly λx.v is a value only when its body is one. The reason is visible in the source language: a Haskell generalization Λa.e must not delay the evaluation of e, because the source program has no abstraction there at all. Since D marks the position of an erased argument rather than deleting it, the reduction rule has to compensate.

Definition 132.3 — Typing

Γ
Γ:
E-Star
Γx:AΓ
Γx:A
E-Var
Γ,x:AB:
ΓΠρx:AB:
E-Pi
Γ,x:Aa:B(ρ=+) or xfv(a)
Γλρx.a:Πρx:AB
E-Abs
Γb:Π+x:ABΓa:A
Γba+:B[a/x]
E-App
Γb:Πx:ABΓa:A
Γb:B[a/x]
E-IApp
Γa:AΓ;Γ~AB:
Γa:B
E-Conv
ΓFa:AΣ0
ΓF:A
E-Fam
Γ,c:ϕB:
Γc:ϕ.B:
E-CPi
Γ,c:ϕa:B
ΓΛc.a:c:ϕ.B
E-CAbs
Γa1:c:(aAb).B1Γ;Γ~ab:A
Γa1[]:B1[/c]
E-CApp
Γa:AΓb:A
ΓaAb ok
E-Wff

Contexts are well formed by the evident three rules, and Γ~ denotes the set of all coercion variables bound in Γ.

Two features of definition 132.3 are worth stating before they are used. The relevance side condition of E-Abs is a condition on the body, not on the type: λx.a is well typed exactly when x does not occur free in a, so an irrelevant argument is parametric in the strong sense that the body cannot inspect it. And E-Wff makes propositions homogeneous: aAb is well formed only when a and b have the same type A. Remark 132.23 records what that choice buys.

Example 132.4 — The one axiom of the signature

Take Σ0={Fixλx.λ+y.(y(Fix  y)):Πx:(xx)x}. This one definition makes D a full-spectrum language with general recursion: every type is inhabited by Fix  (λ+z.z), which by E-Axiom and two E-AppAbs steps reduces to itself. Nothing in this chapter proves termination or logical consistency, and subsection 132.3.1 explains why the property that is proved, and is also called consistency, is a different statement.

Exercise 132.1

★☆☆ Check Fixλx.λ+y.(y(Fix  y)):Πx:(xx)x against the signature rule, naming the rule at each node and checking the side condition of E-Abs at the λ. Then compute the first three reduction steps of Fix  (λ+z.z).

Definitional equality and the available set

Definition 132.5 — Definitional equality

The judgment Γ;Δab:A is generated by the equivalence rules

Γa:A
Γ;Δaa:A
E-Refl
Γ;Δba:A
Γ;Δab:A
E-Sym
Γ;Δaa1:AΓ;Δa1b:A
Γ;Δab:A
E-Trans
Γa1:Ba10a2
Γ;Δa1a2:B
E-Beta

the congruence rules for Π, λ, application, , Λ and coercion application, the injectivity rules

Γ;ΔΠρx:A1B1Πρx:A2B2:
Γ;ΔA1A2:
E-PiFst
Γ;ΔΠρx:A1B1Πρx:A2B2:Γ;Δa1a2:A1
Γ;ΔB1[a1/x]B2[a2/x]:
E-PiSnd

their two analogues E-CPiFst and E-CPiSnd for , the conversion rules E-Cast and E-EqConv, and the assumption rule

Γc:(aAb)ΓcΔ
Γ;Δab:A
E-Assn

The congruence rule for coercion abstraction types is

Γ;Δϕ1ϕ2Γ,c:ϕ1;ΔAB:
Γ;Δc:ϕ1.Ac:ϕ2.B:
E-CPiCong

in which the bound c is not added to Δ.

The judgment is homogeneously typed, and this is the first property to record.

Lemma 132.6 — Regularity of definitional equality

If Γ;Δab:A then Γa:A and Γb:A.

Proof of Lemma 132.6 — Regularity of definitional equality

Proof. Induction on the equality derivation. E-Refl and E-Beta carry the typing of one side as a premise and obtain the other from theorem 132.11. E-Sym and E-Trans are immediate from the induction hypotheses. Each congruence rule reassembles the typing of both sides from the typings supplied by its premises, using the corresponding typing rule. E-Assn reads the proposition aAb out of Γ; since Γ, E-Wff was checked when the binding was formed, so both Γa:A and Γb:A. E-EqConv moves both typings along an equality of types by E-Conv. E-PiFst and E-PiSnd obtain their conclusions by inverting the typing of the two Π-types delivered by the induction hypothesis and applying lemma 132.9 in the second case. ◻

E-Assn is what separates this system from an ordinary intensional type theory: an assumed proposition may be used directly as a definitional equality. That is what makes a GADT branch type check, and it is exactly the feature that forces the available set into the judgment.

Example 132.7 — Why Δ is not simply Γ

Let Int and Bool be two distinct constants of type , and consider ;c:(IntBool).Intc:(IntBool).Bool:. If E-CPiCong added c to Δ when checking the bodies, this equality would be derivable: the propositions are identical, and under c:(IntBool) with c available, E-Assn gives IntBool:. The two sides of the conclusion are then two closed types with different head constants that are definitionally equal in the empty available set — and corollary 132.17 says that cannot happen. The rule as printed does not add c, and remark 132.8 shows the derivation stopping.

Remark 132.8 — What the restriction costs

With cΔ, the derivation of example 132.7 has no step available at the leaf IntBool: E-Assn requires cΔ, E-Beta requires a primitive reduction between two distinct constants, and no congruence rule matches two atoms. The cost is that some equalities that happen to be harmless are not derivable. The restriction is not needed everywhere: in E-CAppCong the premise Γ;Γ~ab:A exists only to make the two coercion applications type check, so it may use the full set. A rule uses Δ exactly where its premise is part of the equality being proved.

Lemma 132.9 — Substitutivity

If Γ1,x:A,Γ2b:B and Γ1;Δa1a2:A then Γ1,Γ2[a1/x];Δb[a1/x]b[a2/x]:B[a1/x].

Proof of Lemma 132.9 — Substitutivity

Proof. Induction on the typing derivation of b, building the equality congruence that matches each typing rule. At E-Var for x the conclusion is the hypothesis; at any other variable, E-Refl. At E-Abs, E-App, E-Pi, E-CAbs and E-CApp the induction hypotheses feed E-AbsCong, E-AppCong, E-PiCong, E-CAbsCong and E-CAppCong, whose available sets are the same Δ in every position that carries the equality. The step that fails in a system whose congruence rules add the bound coercion variable to Δ is E-CAbs: there the body is compared under c:ϕ, and if that comparison had to be carried out in Δ,c the induction hypothesis, stated for Δ, would not apply. Because definition 132.5 keeps Δ fixed, the induction goes through. ◻

Type soundness for D

Lemma 132.10 — Inversion for abstraction

If Γλρx.b0:A then there are A1 and B1 with Γ;Γ~AΠρx:A1B1:, Γ,x:A1b0:B1, Γ,x:A1B1: and ΓA1:.

Proof of Lemma 132.10 — Inversion for abstraction

Proof. Induction on the typing derivation. The derivation ends either in E-Abs, which gives the four conclusions with A=Πρx:A1B1 and the equality by E-Refl, or in E-Conv, whose premise Γλρx.b0:A yields the data by the induction hypothesis and whose equality AA is composed with the returned one by E-Trans. No other rule has a λ as its subject. ◻

Theorem 132.11 — Preservation

If Γa:A and a0a then Γa:A. The same holds for aa.

Proof of Theorem 132.11 — Preservation

Proof. The mechanism is worth naming: conversion makes inversion deliver a type that is only definitionally equal to the one in hand, so each beta case needs the injectivity of the corresponding type former to recover the domain and codomain. That is why E-PiFst, E-PiSnd, E-CPiFst and E-CPiSnd belong to definition 132.5 rather than being derived afterwards.

E-AppAbs. Let Γ(λρx.v)aρ:A. Inverting the application rule gives Γλρx.v:Πρx:A0B0, Γa:A0 and A=B0[a/x]. Lemma 132.10 gives A1,B1 with Γ;Γ~Πρx:A0B0Πρx:A1B1: and Γ,x:A1v:B1. By E-PiFst, Γ;Γ~A0A1:, so E-Conv gives Γa:A1 and lemma 132.9 applied to the typing of v gives Γv[a/x]:B1[a/x]. By E-PiSnd with E-Refl on a, Γ;Γ~B0[a/x]B1[a/x]:, and one more E-Conv returns the type A.

E-CAppCAbs. The same argument with E-CPiFst and E-CPiSnd in place of E-PiFst and E-PiSnd, and with the substitution b[/c] replacing v[a/x].

E-Axiom. E-Fam types F at the A recorded in Σ0, and well-formedness of Σ0 gives a:A; weakening moves it to Γ.

For one-step reduction, E-Prim is the three cases above, and E-AbsTerm, E-AppLeft and E-CAppLeft rebuild the typing derivation from the induction hypothesis using E-Abs, E-App or E-IApp, and E-CApp respectively. In E-AbsTerm the side condition xfv(a) is preserved, because reduction does not introduce free variables. ◻

Consistency

Definition 132.12 — Consistent types

Write consistent A B when it is not the case that A and B are types with different head forms; the head forms are , Πρx:AB, c:ϕ.A and an applied variable or definition.

Definition 132.13 — Joinability

Let ab be parallel reduction. Two terms are joinable, written a1a2, when there is b with a1b and a2b.

The soundness argument now has three steps: equality with an empty available set implies joinability; parallel reduction is confluent; and joinable types are consistent. The middle step is a substantial rewriting theorem and is imported exactly.

Theorem 132.14 — Confluence of parallel reduction; imported

If aa1 and aa2 then there is b with a1b and a2b.

This is Theorem 4.6 of Weirich, Voizard, Azevedo de Amorim, and Eisenberg (2017). It is imported for their parallel reduction, defined for the syntax of definition 132.1 with the signature Σ0 treated opaquely. What it supplies here is exactly the diamond property; every use of it below is through theorem 132.16. No other property of parallel reduction is assumed, and nothing in this chapter reproves it.

Theorem 132.15 — Equality implies joinability

If Γ;ab:A then ab.

Proof of Theorem 132.15 — Equality implies joinability

Proof. Induction on the equality derivation. The available set is empty, so E-Assn cannot fire — this is the one place where the restriction of definition 132.5 does the work, and it is why the theorem is stated with . E-Refl gives aa. E-Beta gives a1a2, since every primitive reduction is a parallel reduction step. E-Sym is symmetry of . E-Trans needs theorem 132.14: from ad1, a1d1, a1d2, bd2, confluence gives a common reduct of d1 and d2, hence of a and b. Every congruence rule is handled by joining the components and reassembling, because parallel reduction is a congruence. E-PiFst, E-PiSnd, E-CPiFst and E-CPiSnd are handled by observing that a common reduct of two Π-types is a Π-type whose components are common reducts of the components, again by theorem 132.14. ◻

Theorem 132.16 — Joinability implies consistency

If AB then A and B are consistent in the sense of definition 132.12.

Proof of Theorem 132.16 — Joinability implies consistency

Proof. Parallel reduction does not change the head form of , Πρx:AB or c:ϕ.A: no reduction rule has one of these as a redex, and the congruence clauses rebuild the same head. So if Ab and Bb and both A and B are in head form, both heads equal the head of b. ◻

Corollary 132.17 — Consistency for D

If Γ;ab:A then consistent a b.

Remark 132.18

Two different statements are called consistency in this subject. Corollary 132.17 says that definitional equality does not identify two types with different heads; it is the canonical-forms input to theorem 132.19. Logical consistency — the existence of an uninhabited type — is false here, because example 132.4 inhabits every type. A Dependent Haskell term is therefore never a proof of the proposition its type encodes, and no result in this chapter should be read as saying otherwise.

Theorem 132.19 — Progress

If Γa:A, Γ contains no coercion assumption, and no term variable in dom(Γ) occurs free in a, then either a is a value or aa for some a.

Proof of Theorem 132.19 — Progress

Proof. Induction on the typing derivation. E-Star, E-Pi and E-CPi give values. E-Var cannot occur, since a has no free term variable. E-Fam gives an E-Axiom step. E-Conv passes to its premise.

E-Abs. If ρ=+ the term is a value. If ρ=, the induction hypothesis applies to the body in Γ,x:A; the extra binding is a term variable that does not occur free in the body, by the side condition of E-Abs, so the hypothesis of the theorem is preserved. Either the body is a value, and then λx.a is one, or the body steps, and E-AbsTerm lifts the step.

E-App and E-IApp. Apply the induction hypothesis to the function. If it steps, E-AppLeft lifts the step. If it is a value v of type Πρx:A0B0, then corollary 132.17 applies: by lemma 132.10 and the value grammar, v is one of λρx.b, , a Π-type, a -type or Λc.b. A closed value of the last four shapes has type or a -type, and Γ; that type Πρx:A0B0 would identify two different head forms, contradicting corollary 132.17. The available set is empty because Γ has no coercion assumption. Hence v=λρx.b and E-AppAbs applies.

E-CApp. The same argument, with the head form, gives v=Λc.b and an E-CAppCAbs step. ◻

Exercise 132.2

★★☆ Show that theorem 132.19 fails if the hypothesis “Γ contains no coercion assumption” is deleted, by giving a well-typed term in a context with one coercion assumption that is neither a value nor reducible. Then say which step of the proof breaks and which theorem it appealed to.

Exercise 132.3

★★☆ Suppose E-CPiCong added the bound c to Δ. Using example 132.7, exhibit a closed derivation of ;IntBool: in the resulting system. Identify the first line of the proof of theorem 132.15 that becomes false, and the case of theorem 132.19 that then fails.

System DC

D is not a checker: E-Conv has an undecidable premise, and E-App guesses the type of an abstraction’s argument. DC reifies the derivation.

Definition 132.20 — Syntax of DC

a,b,A,B::=xFλρx:A.babρΠρx:ABΛc:ϕ.aa[γ]c:ϕ.Aaγ,γ::=crefl asym γγ1;γ2red abΠρx:γ1.γ2 Neither nor occurs: an irrelevant application carries its actual argument, and a coercion application carries an explicit proof.

Definition 132.21 — Typing for DC

Γ,x:Aa:B(ρ=+) or xfv(|a|)
Γλρx:A.a:Πρx:AB
An-Abs
Γb:Πρx:ABΓa:A
Γbaρ:B[a/x]
An-App
Γa:AΓ;Γ~γ:ABΓB:
Γaγ:B
An-Conv
Γa1:c:aA1b.BΓ;Γ~γ:ab
Γa1[γ]:B[γ/c]
An-CApp

The remaining rules An-Star, An-Var, An-Pi, An-Fam, An-CPi and An-CAbs are those of definition 132.3 with the annotations added.

Three changes carry the whole difference. An-Abs checks relevance against the erasure of the body, because the annotation A may legitimately mention x; An-App needs no separate irrelevant rule, because the argument is present in both cases; and An-Conv replaces the undecidable equality premise by a proof γ that the checker only has to verify.

Definition 132.22 — Coercion checking, excerpt

Γa:A
Γ;Δrefl a:aa
An-Refl
Γc:aAbΓcΔ
Γ;Δc:ab
An-Assn
Γa1:B0Γa2:B1|B0|=|B1||a1|0|a2|
Γ;Δred a1a2:a1a2
An-Beta
Γ;Δγ:Πρx:A1B1Πρx:A2B2
Γ;ΔpiFst γ:A1A2
An-PiFst

The congruence rules carry one extra piece of bookkeeping. For instance An-PiCong compares the codomains under a variable of the left domain and repairs the right-hand side by substitution:

Γ;Δγ1:A1A2Γ,x:A1;Δγ2:B1B2B3=B2[xsym γ1/x]
Γ;ΔΠρx:γ1.γ2:Πρx:A1B1Πρx:A2B3
An-PiCong

Remark 132.23 — Why the coercion judgment is heterogeneous in its terms

The D proposition aAb is homogeneous by E-Wff: the two terms have one type. The DC coercion judgment Γ;Δγ:ab does not record a type, and its regularity statement is weaker.

Lemma 132.24 — Coercion regularity for DC

If Γ;Δγ:ab then there are A, B and γ0 with Γa:A, Γb:B and Γ;Γ~γ0:AB.

This is Lemma 5.6 of Weirich, Voizard, Azevedo de Amorim, and Eisenberg (2017). Three weaker alternatives were available — requiring A=B, requiring A and B to be α-equivalent, or requiring nothing — and the reason for this one is compositionality: with A=B, the congruence rule for application would have to insert a coercion around one side to make the two dependent result types agree, and would no longer be symmetric in its two premises.

Lemma 132.25 — Decidability and uniqueness

Given Γ and a, it is decidable whether there is A with Γa:A; and if Γa:A1 and Γa:A2 then A1=A2.

Proof of Lemma 132.25 — Decidability and uniqueness

Proof. Uniqueness is by induction on a: every rule of definition 132.21 is determined by the outermost form of its subject, and each reads its result type off the subject’s annotations — An-Abs from A and the body’s unique type, An-App by substituting the actual argument, An-Conv from the coercion’s right-hand side, An-CApp by substituting the supplied proof. Since there is no rule whose subject is arbitrary, no conversion rule applies silently. Decidability follows: the syntax-directed reading of the rules is a terminating recursion on a, whose only non-structural obligation is checking a coercion, and definition 132.22 is likewise syntax directed on γ, with An-Beta requiring only one primitive reduction step of an erased term and a syntactic comparison. ◻

Erasure and annotation

Definition 132.26 — Annotation erasure

||=,|x|=x,|F|=F,|λρx:A.a|=λρx.|a|,|ab+|=|a||b|+,|ab|=|a|,|Πρx:AB|=Πρx:|A||B|,|Λc:ϕ.a|=Λc.|a|,|a[γ]|=|a|[],|aγ|=|a|,|c:a0Aa1.b|=c:|a0||A||a1|.|b|.

The clause |ab|=|a| is the one that answers the opening obstruction: the argument disappears, the application site does not. The clause |aγ|=|a| deletes every equality proof, exactly as in chapter 131.

Lemma 132.27 — Erasure and annotation

If Γa:A then |Γ||a|:|A|. Conversely, if Γa:A then for every Γ0 with |Γ0|=Γ there are a0 and A0 with Γ0a0:A0, |a0|=a and |A0|=A.

Proof of Lemma 132.27 — Erasure and annotation

Proof of the first half. Induction on the DC typing derivation, rule by rule. An-Star, An-Var, An-Fam, An-Pi and An-CPi erase to the identically named D rules. An-Abs erases to E-Abs: its side condition is stated on |a|, which is exactly the side condition of E-Abs at the erased body. An-App at ρ=+ erases to E-App; at ρ= it erases to E-IApp, whose premise Γa:A is supplied by the induction hypothesis applied to the actual argument that DC carries and D deletes. An-CAbs erases to E-CAbs. An-CApp erases to E-CApp, its coercion premise becoming the equality premise by the erasure of the coercion judgment. An-Conv erases to E-Conv, because the erasure of aγ is |a| and the coercion becomes a definitional equality. The second half is Lemma 5.5 of the frozen source; its proof constructs annotations by recursion on the D derivation and is not reproduced here. ◻

Lemma 132.28 — Reduction erasure

If Γab and Γa:A then |a||b| or |a|=|b|.

The steps that erase to an equality are exactly those that only move an annotation or a cast; the pattern is the same as theorem 131.35 of chapter 131, and it is what licenses the following reading of the two languages.

Corollary 132.29 — Annotations do not change behaviour

If Γa1:A1 and Γa2:A2 with |a1|=|a2|, then a1 and a2 have the same erased reduction behaviour.

Proof of Corollary 132.29 — Annotations do not change behaviour

Proof. Both erase to the same D term, and by lemma 132.28 every DC step of either projects to a step or to nothing in D. Since D reduction is deterministic, the two erased reduction sequences coincide. ◻

That is the practical content of the pair D/DC. In the zip of the opening, a type inferencer may produce the empty-vector branch with the proof c1 or with the proof c2; the two annotated programs are different DC terms, they erase to the same D term, and corollary 132.29 says the choice is invisible at run time.

Exercise 132.4

★★☆ Write the two DC versions of the empty-vector branch of zip described above, erase both by definition 132.26, and check that the results are identical. Then exhibit two DC terms with the same erasure but different types, and say why that does not contradict lemma 132.25.

Exercise 132.5

★★☆ An-Abs checks xfv(|a|) rather than xfv(a). Give a DC term that is well typed under the printed rule and ill typed under the stricter one, and explain in one sentence which occurrence of x the erasure deletes.

Limits and seminar

The frozen source is Weirich, Voizard, Azevedo de Amorim and Eisenberg (2017), together with its Coq development. Every rule displayed above is theirs, and the theorem statements retain their exact hypotheses: theorem 132.15 holds only for the empty available set; theorem 132.19 holds only for contexts without coercion assumptions and without free term variables; lemma 132.24 relates the types of the two sides only up to a derivable equality. Theorem 132.14 is imported, not reproved.

Four boundaries are worth stating plainly. First, nothing here is a theorem about GHC. D and DC have no primitive datatypes, no pattern matching, no type classes and no roles; the vector examples are encodings, and the compiler’s front end is not modelled. Second, corollary 132.17 is not logical consistency, and example 132.4 shows why: every type is inhabited. Third, the signature Σ0 is treated opaquely, so the results hold for any well-formed signature but say nothing about a particular set of recursive definitions beyond its well-formedness. Fourth, D’s type system is undecidable, so lemma 132.25 is a statement about DC only; the implicit language is a specification and an inspiration for inference, not an algorithm.

The relation to chapter 131 is one of replacement, not extension. FC keeps a syntactic separation of types from terms and erases the former; DC conflates them and erases whatever is marked ρ=. A coercion is explicit in both, and both admit an erasure theorem, but no FC theorem transfers to DC by that resemblance: FC’s consistency is a condition on top-level axioms, whereas D’s is a proved property of definitional equality with an empty available set.

[4]

Suggested first pass.

None of these problems is a prerequisite for a later chapter. Begin with exercise 132.6, then complete exercise 132.9.

Exercise 132.6

★★☆ Encode the two-constructor vector type of the opening as a Scott-encoded D term, give the type of the cons constructor including its equality constraint, and type the empty-vector branch of zip, naming the use of E-Assn and the available set at that point.

Exercise 132.7

★★★ The impossible branches of zip are discharged by a contradiction between n0 and nSuccm. Write the D derivation that takes those two assumptions to an equality of two constructor applications with different heads, and then explain why corollary 132.17 does not apply to it. State precisely what has to be true of the context for the branch to be unreachable.

Exercise 132.8

★★★ Consider three candidate variants of E-CPiCong: the printed rule; the rule that adds c to Δ; and the rule that requires ϕ1=ϕ2 syntactically. For each, say whether theorem 132.15, lemma 132.9 and theorem 132.19 survive, giving either a proof sketch of the surviving case or a counterexample.

Exercise 132.9 — Practical: relevance and erasure checker

★★★ Practical project.dc-relevance-erasure Complete project dc-relevance-erasure. Implement, for a finite fragment of D and DC, (i) the DC typing rules An-Star, An-Var, An-Abs, An-App, An-CAbs, An-CApp and An-Conv, (ii) the annotation erasure of definition 132.26, (iii) the D one-step reduction of definition 132.2 including E-AbsTerm, and (iv) the head-form consistency test of definition 132.12. The invariant the implementation must maintain is that a term accepted by the DC checker erases to a term accepted by the D checker at the erased type, so that lemma 132.27 holds on every accepted input. The named cases print

irrelevant-use: rejected
erased-application: ok
two-annotations-one-erasure: ok
reduce-under-irrelevant: value
int-bool: inconsistent

The checker is independent evidence for the finite fragment; it does not prove theorem 132.11, theorem 132.19, does not decide D typing, and does not implement the coercion language of definition 132.22 beyond An-Refl, An-Assn and An-Beta.

Search the book

Type to search the local edition.