1.2 The Type System F
1.2.1 Adding Sum and Product Types
Although systemFis highly expressive we prefer to add sum and product types to our basic framework for comfort and because of some technicalities that will be clear later.
1.2. THE TYPE SYSTEMF 15
Extend systemF as follows: Types:
σ, ρ::=. . . |σ+ρ|σ×ρ
Terms :
t, r, s ::= . . . | inlr| inrs|case(r, x.s, y.t)| hr, si |π1r|π2r Type Assignment: r:ρ inlr:ρ+σ (+IL) r:σ inrr:ρ+σ (+IR) r:ρ+σ , x:ρs:τ , y:σt:τ case(r, x.s, y.t) :τ (+E) r:ρ s:σ hr, si:ρ×σ (×I) s:ρ×σ π1s:ρ (×EL) s:ρ×σ π2s:σ (×ER) Reduction Relation:
case(inlr, x.s, y.t) 7→β s[x:=r]
case(inrr, x.s, y.t) 7→β t[y:=r] π1hr, si 7→β r π2hr, si 7→β s
We call to this extensionF+,×.
F+,×
enjoys subject reduction which can be proven by adapting the method for system Fin [Kri93].
Strong normalization can be proved by embedding it into systemF. Nevertheless and in the spirit of modularity we reprove strong normalization via Matthes’
SN-method developed in [Mat98], later we will extend this proof to the basic system of (co)inductive types.
Strong Normalization for F+,×
Definition 1.12 Let ? be a new symbol. An elimination is an expression of one of the following forms:
?s, case(?, x.t, y.r), π1?, π2?
Definition 1.13 Multiple eliminations are defined as follows: E::=?|e[?:=E]
where e[?:=E] is defined as if ?were a term variable. From now on we will useE[r] to denote E[?:=r].
Definition 1.14 The setSNis inductively defined as follows:
x∈SN E[x], s∈SN E[x]s∈SN E[x], s, t∈SN case(E[x], x.s, y.t)∈SN E[x]∈SN π1(E[x])∈SN E[x]∈SN π2(E[x])∈SN r∈SN λxr∈SN Er[x:=s], s∈SN E[(λxr)s]∈SN t∈SN inlt∈SN t∈SN inrt∈SN Er[x:=t], s∈SN
E[case(inlt, x.r, y.s)]∈SN
Es[y:=t], r∈SN
Ecase(inrt, x.r, y.s)∈SN
r, s∈SN hr, si ∈SN E[r], s∈SN E[π1hr, si]∈SN E[s], r∈SN E[π2hr, si]∈SN
Definition 1.15 (Saturated Set) A setM of terms is saturated iff:
M ⊆SN
and if the following closure conditions hold: E[x]∈SN
E[x]∈ M
Er[x:=s]∈ M s∈SN
E[(λxr)s]∈ M
Er[x:=t]∈ M s∈SN
E[case(inlt, x.r, y.s)]∈ M
Es[y:=t]∈ M r∈SN
Ecase(inrt, x.r, y.s)∈ M
E[r]∈ M s∈SN
E[π1hr, si]∈ M
E[s]∈ M r∈SN
E[π2hr, si]∈ M
the set of saturated sets will be denoted with SAT,
Lemma 1.1 The following holds:
◦ SN∈SAT
1.2. THE TYPE SYSTEMF 17
Proof. Straightforward a
Definition 1.16 Given a set of termsM we define the saturated closure ofM as follows:
cl(M) :=\{N ∈SAT|M∩SN⊆ N }
cl(M) is the least saturated set which containsM∩SN. Observe that M⊆
cl(M) if and only ifM ⊆SN.
Definition 1.17 Given a variable x andM,N ∈SATwe define
Sx(M,N) :={t| ∀s∈ M. t[x:=s]∈ N }
Definition 1.18 GivenM,N ∈SAT, we define the following sets:
I→(M,N) := {λxt|t∈Sx(M,N)}
I+(M,N) := {inlt|t∈ M} ∪ {inrt|t∈ N } I×(M,N) := {hs, ti |s∈ M andt∈ N } M → N := cl(I→(M,N)) M+N := cl(I+(M,N)) M × N := cl(I×(M,N)) E→(M,N) := {r∈SN| ∀s∈ M. rs∈ N } E+(M,N) := {r∈SN| ∀P∀x∀s∈Sx(M,P)∀y∀t∈Sy(N,P). case(r, x.s, y.t)∈ P} E×(M,N) := {r∈SN|π1r∈ M andπ2r∈ N }
Lemma 1.2 For ∈ {→,+,×}we haveI(M,N)⊆SN.
Proof. The proof is straightforward, as example we show the case=×. Take hs, ti ∈ I×(M,N), i.e., s ∈ M and t ∈ N, but as M,N ∈ SAT we have
Corollary 1.1 For ∈ {→,+,×}and the same in both choices, we have
I(M,N)⊆ M N.
Proof. Again we only treat the case for = ×. We have to show that I×(M,N)⊆ M × N, but by definitionM × N =cl(I×(M,N)) and we know
thatI×(M,N)∩SN⊆cl(I×(M,N)), which by the previous lemma is the same
asI×(M,N)⊆cl(I×(M,N)) and we are done. a
Lemma 1.3 For ∈ {→,+,×} we haveE(M,N)∈SAT.
Proof. The proof is straightforward, as example we treat the case for =×. E×(M,N) ⊆ SN is clear. Take E[r[x := s] ∈ E×(M,N) and s ∈ SN, we
have to show E[(λxr)s] ∈ E×(M,N). As E[ r[x :=s] ∈ E×(M,N) we have π1(E[r[x :=s])∈ M and π2(E[ r[x:=s])∈ N. Observe that π1(Er[x := s])≡(π1?) ?:=Er[x:=s]≡(π1?)[?:=E] r[x :=s] and that (π1?)[?:=
E] is again a multiple elimination sayE0, therefore we haveE0r[x:=s]∈ M,
and as s ∈ SN and M ∈ SAT we get E0[(λxr)s] ∈ SN, i.e., π1(E[(λxr)s]) ∈
M. Analogously we show that π2(E[(λxr)s]) ∈ N. Therefore E[(λxr)s] ∈
E×(M,N). The other rules forSATsets are proved similarly. a
Lemma 1.4 For ∈ {→,+,×} and the same in both choices, we have
I(M,N)⊆ E(M,N).
Proof. For = × take hs, ti ∈ I×(M,N). We have to show that hs, ti ∈
E×(M,N), i.e.,π1hs, ti ∈ M andπ2hs, ti ∈ N. Ashs, ti ∈ I×(M,N) we have s∈ M and t∈ N. Observe that s≡ ?[s] ∈ M is a multiple elimination and
t∈SN, becauseN ⊆SN. Therefore asM ∈SAT, we have?[π1hs, ti]∈ M. i.e.,
π1hs, ti ∈ Mand analogouslyπ2hs, ti ∈ N. a
Corollary 1.2 For ∈ {→,+,×}and the same in both choices, we have
M N ⊆ E(M,N).
Proof. We have to show thatM N ≡cl(I(M,N))⊆ E(M,N). But by the
previous lemmas we have that I(M,N) ⊆ E(M,N) and that E(M,N) ∈
SATtherefore by minimality of the closure we are done. a Proposition 1.7 (Saturated Sets Properties) AssumeM,N ∈SAT, then
1. M → N ∈SAT
2. Ifr∈ M → N ands∈ Mthenrs∈ N. 3. Ift∈Sx(M,N) thenλxt∈ M → N.
1.2. THE TYPE SYSTEMF 19
4. M+N ∈SAT
5. Ift∈ Mthen inlt∈ M+N. 6. Ift∈ N theninrt∈ M+N.
7. Ifr∈ M+N, s∈Sx(M,P), t∈Sy(N,P)thencase(r, x.s, y.t)∈ P 8. M × N ∈SAT 9. Ifs∈ M andt∈ N thenhs, ti ∈ M × N 10. Ifr∈ M × N thenπ1r∈ Mandπ2r∈ N Proof. 1. Clear. 2. Immediate fromM → N ⊆ E→(M,N).
3. Taket∈Sx(M,N), this impliesλxt∈ I→(M,N)⊆ M → N.
4. Clear. 5. t∈ Mimpliesinlt∈ I+(M,N)⊆ M+N. 6. t∈ N impliesinrt∈ I+(M,N)⊆ M+N. 7. Immediate fromM+N ⊆ E+(M,N). 8. Clear. 9. s∈ M, t∈ N implyhs, ti ∈ I×(M,N)⊆ M × N. 10. Immediate fromM × N ⊆ E×(M,N). a
Definition 1.19 A candidate assignment is a finite set of pairs of the form α:Mwhereαis a type variable andM ∈SATsuch that no type variable occurs twice. Candidate assignments are denoted withΓ, in the expressionΓ, α:Mis understood that α /∈Γ.
Definition 1.20 (Strong Computability Predicates) Given a type ρ and a candidate assigmentΓwe define the saturated set of strongly computable terms
with respect toρandΓ,denotedSCρ[Γ], as follows: SCα[Γ] := M if α:M ∈Γ SN otherwise. SCρ→σ[Γ] := SCρ[Γ]→SCσ[Γ] SCρ+σ[Γ] := SCρ[Γ] +SCσ[Γ] SCρ×σ[Γ] := SCρ[Γ]×SCσ[Γ] SC∀αρ[Γ] := TM∈SATSCρ[Γ, α:M]
Lemma 1.5 (Coincidence) If α /∈F V(ρ)then SCρ[Γ, α:M] =SCρ[Γ]. Proof. Induction on ρ.
Ifρ≡β6=αwe have two possibilites, ifβ :N ∈Γ thenSCβ[Γ, α:M] =N =
SCβ[Γ], otherwiseSCβ[Γ, α:M] =SN=SCβ[Γ]. Forρ≡ ∀βσ, we can assume
β /∈Γ andα6=β, thenSC∀βσ[Γ, α:M] =TN ∈SATSCσ[Γ, α:M, β:N] which by IH, asα /∈F V(σ), equalsTN ∈SATSCσ[Γ, β:N] =SC∀βσ[Γ]. a Lemma 1.6 (Substitution) SCρ[α:=σ][Γ] =SCρ[Γ, α:SCσ[Γ]].
Proof. Induction onρ. Ifρ=αthenSCα[α:=σ][Γ] =SCσ[Γ] which by definition is the same asSCα[Γ, α:SCσ[Γ]]. If ρ≡β 6=αwe haveSCβ[α:=σ][Γ]≡SCβ[Γ] which by the coincidence lemma is the same asSCβ[Γ, α:SCσ[Γ]].
Case ρ ≡ ∀βτ. We can assume β 6= α and β /∈ F V(σ). SC(∀βτ)[α:=σ][Γ] =
T
N ∈SATSC
τ[α:=σ][Γ, β : N], which by IH equals T
N ∈SATSC
τ[Γ, β : N, α :
SCσ[Γ, β : N]] = TN ∈SATSCτ[Γ, α : SCσ[Γ, β : N], β : N], which using the coincidence lemma (β /∈F V(σ)) simplifies toTN ∈SATSCτ[Γ, α:SCσ[Γ], β :N]. But this is exactlySC∀βτ[Γ, α:SCσ[Γ]].
a Lemma 1.7 (Main Lemma) If r:ρwith ={x1:ρ1, . . . , xk :ρk}and
si∈SCρi[Γ], for 1≤i≤k, thenr[~x:=~s]∈SCρ[Γ].
Proof. Induction on . Case (→ I) Assume λxt : ρ → σ from , x :
ρt:σ. Our goal is (λxt)[~x:=~s]∈SCρ→σ[Γ], i.e.,λx.t[~x:=~s]∈SCρ[Γ]→ SCσ[Γ]. Using the proposition 1.7, part 3, it suffices to show t[~x := ~s] ∈
Sx(SCρ[Γ],SCσ[Γ]). Take r ∈ SCρ[Γ], we have to prove that t[~x := ~s][x := r] ∈ SCσ[Γ]. The IH implies t[~x, x:= ~s, r] ∈ SCσ[Γ], but we have x /∈ ~xand w.l.o.g. alsox /∈F V(~s) thereforet[~x, x:=~x, r]≡t[~x:=~s][x :=r] and we are done.
Case (∀I) Assume t:∀ατ from t:τ andα /∈F V( ). si∈SCρi[Γ] and
α /∈F V(ρi) imply by the coincidence lemmasi ∈SCρi[Γ, α:M], which by IH impliest[~x:=~s]∈SCτ[Γ, α:M] for allM ∈SAT, i.e., t[~x:=~s]∈SC∀ατ[Γ]. Case (∀E). Assume t : τ[α := σ] from t : ∀ατ. By IH we have
1.2. THE TYPE SYSTEMF 21
In particular we have t[~x:=~s]∈SCτ[Γ, α:SCσ[Γ]] which, using the substitu- tion lemma, is the same as t[~x:=~s]∈SCτ[α:=σ][Γ].
a Proposition 1.8 If r:ρthenr∈SN.
Proof. Assume ={x1:ρ1, . . . , xk :ρk}. As the set of variables is contained in every saturated set we havexi∈SCρi[∅] therefore as r:ρthe main lemma
yieldsr[~x:=~x]∈SCρ[∅]⊆SN. Thereforer∈SN. a Terms in SNare Strongly Normalizing
Definition 1.21 The setsnof strongly normalizing terms is inductively defined as follows:
If for every r0 such that r→βr0 we have r0∈sn thenr∈sn.
Lemma 1.8 sn is the set of termsr such that there is no infinite β-reduction sequence starting inr.
Proof. To prove that given a termr∈snthere is no infinite reduction sequence starting in r we simply do induction on r ∈sn. For the reverse inclusion use bar induction, i.e., show that{s|r→?
βs} ⊆snby induction on→β. a
Lemma 1.9 Variables belong tosn.
Proof. Clear a
Lemma 1.10 If E[x], s∈sn thenE[x]s∈sn.
Proof. Main Induction onE[x]∈sn, side induction ons∈sn. a Lemma 1.11 If r∈sn thenλxr∈sn.
Proof. Induction on r∈sn. a
Lemma 1.12 If E[r[x:=s]], s∈sn thenE[(λxr)s]∈sn.
Proof. Main Induction ons∈sn, side induction onE[r[x:=s]]∈sn. a Lemma 1.13 If r, s∈sn thenhr, si ∈sn.
Proof. Main Induction onr∈sn, side induction on s∈sn. a
Lemma 1.14 If E[x]∈sn thenπ1(E[x])∈sn andπ2(E[x])∈sn.
Proof. Induction on E[x]∈sn. a
Lemma 1.15 If E[r], s∈sn thenE[π1hr, si]∈sn
Proof. Main induction ons∈sn, side induction onE[r]∈sn. a Lemma 1.16 If E[s], r∈sn thenE[π2hr, si]∈sn
Proof. Analogous to the previous lemma a
Lemma 1.17 If E[x], r, s∈snthen case(E[x], y.r.z.s)∈sn.
Lemma 1.18 If r∈sn theninlr∈snandinrr∈sn.
Proof. Induction on r∈sn. a
Lemma 1.19 If E[s[y:=t]]∈snandr∈sn thenE[case(inrt, x.r, y.s)]∈sn
Proof. Main induction onr∈sn, side induction onE[s[y:=t]]∈sn. a Lemma 1.20 If E[r[x:=t]]∈snands∈snthen E[case(inlt, x.r, y.s)]∈sn
Proof. Analogous to the previous lemma a
Proposition 1.9 SN⊆sn
Proof. The above lemmas show thatsnis closed under the defining rules ofSN, therefore the claim follows by minimality ofSN. a Proposition 1.10 F+,×strongly normalizes.
Proof. Immediate from propositions 1.8 and 1.9 a
Corollary 1.3 F is strongly normalizing.