A Syntactic Approach To Eta Equality in Type Theory: Healfdene Goguen
A Syntactic Approach To Eta Equality in Type Theory: Healfdene Goguen
Healfdene Goguen
AT&T Labs
180 Park Ave.
Florham Park NJ 07932 USA
hhg@att.com
ABSTRACT of type theories with the additional equality rules. This con-
This paper outlines an elementary approach for showing trasts with other approaches to η-reduction by not requir-
the decidability of type checking for type theories with βη- ing extensive redevelopment for a βη-system given existing
equality, relevant to foundations for modules systems and results for the β-system. Philosophically, our approach ex-
type theory-based proof systems. The key to the approach is plains uniqueness rules without a clear computational justi-
a syntactic translation mapping terms in the βη presentation fication in terms of the well-understood computational rules.
into their full η-expansions in the β presentation. Decidabil- We begin by studying Martin-Löf’s Logical Framework
ity of type checking is lifted from the target β presentation with Π-kinds and βη equality. In this case βη reduction is
to the βη presentation. The approach extends to other in- strongly normalizing and Church–Rosser, and so we could
ductive kinds with a single constructor, and is demonstrated use this relation directly to implement an algorithm for test-
for singletons and dependent pairs. ing conversion.
We follow by studying the extension of the Logical Frame-
work with singletons and dependent pairs at the level of
Categories and Subject Descriptors kinds, similar to that of Stone and Harper [22], although
F.4.1 [Theory of Computation]: Lambda calculus and our singletons include explicit term constructors and elimi-
related systems nation constants. This language has the key difficulties that
the equalities are type-directed and that the η-equalities di-
rected as reductions do not have the Church–Rosser prop-
General Terms erty, and so conversion must be implemented by a cus-
Theory, Languages tomized algorithm, as done by Stone and Harper, or by
conversion in the target language as we do here.
Our development of the metatheory begins by defining the
Keywords source language with the additional η-style equalities over
Logical frameworks, type checking, decidability, beta-eta fully decorated terms, as introduced by Streicher [23] but
equality with full labels for variables and abstraction. Each term
constructor contains explicit labels allowing the reconstruc-
tion of the premises in the rule of inference; for example,
1. INTRODUCTION the application constructor AppB x:A (M, N ) allows us to infer
In this article we introduce an elementary approach to the that M must have kind Πx : A.B and N must have kind A,
metatheory of type theories with βη-style equalities. These even from a judgement Γ ` AppB x:A (M, N ) : C. Because of
weakly extensional equational theories have applications to this explicit information in the term structure, we are able to
programming languages, especially for understanding mod- define a total translation from terms in the source language
ules systems like that of Standard ML [20], to categorical into the target language, without reference to derivations of
combinators [18] and systems of explicit substitution [1], and well-kindedness.
to the foundations of type theory-based proof assistants [19]. We reuse the basic definition of type-directed η-expansion,
Our intention in this article is to justify the weakly exten- like that used in defining η-long normal forms [6, 9]. The
sional η rules by translating them into a system with only the new approach taken here is to apply that expansion to ev-
traditional β-style computation rules. Practically, our ap- ery subterm of the source term. The labels in the fully dec-
proach provides a short and direct proof of the decidability orated terms are used to provide the kind information for
the η-expansion of each term constructor. We give a simple
proof that the translation function preserves substitution,
and the soundness of the translation follows by induction
Permission to make digital or hard copies of all or part of this work for on derivations of the source language.
personal or classroom use is granted without fee provided that copies are The target language of the interpretation is formed from
not made or distributed for profit or commercial advantage and that copies β-equality over unlabeled terms, i.e. the terms of the un-
bear this notice and the full citation on the first page. To copy otherwise, to typed λ-calculus. This is necessary because β-reduction un-
republish, to post on servers or to redistribute to lists, requires prior specific
permission and/or a fee.
der the translation does not preserve the kind labels of η-
POPL’05, January 12–14, 2005, Long Beach, California, USA. reduction: writing ηA (M ) for the η-expansion of M at kind
Copyright 2005 ACM 1-58113-830-X/05/0001 ...$5.00.
A, we only have that ηΠx:C.D (AppD B A
x:C (λx:A (M ), x )) reduces extend the proofs to singletons and dependent pairs, and in
D B
to λx:C (M ), not to λx:A (M ) as would be required by a fully Section 8 we summarize and outline future work.
decorated term language.
Γ, x : A `+ M : B Γ `+ N : A
`+ Γ valid x : A ∈ Γ +
Γ ` [N/x]M : [N/x]B
(Var)
Γ `+ xA : A (β)
Γ `+ AppB B
x:A (λx:A (M ), N ) = [N/x]M : [N/x]B
Γ `+ A kind Γ, x : A `+ B kind
Γ, x : A `+ M : B Γ `+ M : Πx : A.B
(λ) (η) B
Γ `+ λB Γ `+ λB A
x:A (Appx:A (M, x ))
= M : Πx : A.B
x:A (M ) : Πx : A.B
3. BASIC METATHEORY • x : A ∈ λC
y:B (M ) if x 6= y, x : A ∈ B, x : A ∈ C and
x : A ∈ M.
3.1 Properties of the Source Language
• x : A ∈ AppC
x:B (M, N ).
Lemma 1. If Γ `+ + • If Γ `+
βη B kind and x : A ∈ Γ then x : A ∈ B.
βη M : A then Γ `βη M : P(M ) as a
subderivation, and either P(M ) ≡ A or Γ `+ P(M ) =βη
A kind as a subderivation. • If Γ `+
βη M : B and x : A ∈ Γ then x : A ∈ M .
AppD B
x:C (λx:A (M ), N ) β [N/x]M Lemma 3.
Proposition 1. 1. If Γ `− −
β M : A then Γ `β ηA (M ) : A.
1. If Γ `+
β M : A then FV(M ) ∪ FV(A) ⊆ dom(Γ).
2. If Γ `− −
β M = N : A then Γ `β ηA (M ) = ηA (N ) : A.
3.3 The Unlabeled Target Language Definition 4. Define H(A) and H(M ) by structural in-
The judgements in the unlabeled system have the prop- duction:
erties of Proposition 1, as well as the following standard
H(Type) = Type
properties.
H(El(P )) = El(H(P ))
Proposition 2. H(Πx : A.B) = Πx : H(A).H(B)
H(xA ) = ηH(A) (x)
β M : A and M β N then Γ `β N : A.
1. If Γ `− −
H(λB
x:A (M )) = ηΠx:H(A).H(B) (λx.H(M ))
2. If Γ `−
β M : A then M is strongly normalizing under
β . H(AppB
x:A (M, N )) = η[H(N )/x]H(B) (H(M )(H(N )))
The H(−) map extends to contexts in the obvious way.
3. Typechecking for `−
β is decidable.
Lemma 5. ηH(P(M )) (H(M )) ∗β H(M ). Furthermore, if
4. SOUNDNESS P(M ) ≡ Πx : A.B then ηH(Πx:A.B) (H(M )) +
β H(M ).
We now show that the η-expansions of terms typable in Proof. By induction on M , using Lemma 4 Case 3 di-
the βη-system are typable in the β-system. rectly for each term constructor.
We begin by defining two maps on terms, ηA (−) and
H(−). Intuitively, ηA (M ) represents the η-expansion of M The following lemma is similar to typical substitution lem-
at kind A, and H(M ) replaces all subterms of M with their mas. We need to include the side condition that x not occur
η-expansions at their principal kinds. This translation in- free in its kind because the definition of H(−) is for arbitrary
serting η-expansions through all subterms clearly models η terms and kinds, not only well-formed ones, and so imposes
equality, since the subterm M in an η-redex λB D E
x:A (Appx:C (M, x )) no conditions on subterms of its argument. The side con-
will be translated to a λ-abstraction, and so the translation dition will always hold for terms and kinds in well-formed
of the η-redex is β-equal to the translation of its reduct. judgements.
Lemma 6. by Lemma 3, and
1. If x : C ∈ A, H(C) =β H(P(P )) and x 6∈ FV(H(C)) H(Γ) `− [H(N )/x]H(B) =β H([N/x]B) kind
then [H(P )/x]H(A) ∗β H([P/x]A).
by Lemma 6, Proposition 1 Case 4 (for `− ) and Sub-
2. If x : C ∈ M , H(C) =β H(P(P )) and x 6∈ FV(H(C)) ject Reduction (Proposition 2 Case 1), so H(Γ) `−β
then [H(P )/x]H(M ) ∗β H([P/x]M ). H(AppB x:A (M, N )) : H([N/x]B) by Eq.
Proof. By induction on A and M . We consider several
• β. By induction hypothesis H(Γ) `− H(λB x:A (M )) :
cases.
H(Πx : A.B) and H(Γ) `− H(N ) : H(A), so H(Γ) `−
• xA . Then: H(AppB B
x:A (λx:A (M ), N )) ≡ η[H(N )/x]H(B) (H(M )(H(N ))) :
[H(N )/x]H(B) =β H([N/x]B) by Lemma 3 and rea-
[H(P )/x]ηH(A) (x) soning similar to App for the kind equality. Further-
≡ η[H(P )/x]H(A) (H(P )) more, by inversion Γ, x : A `+ M : B, so x : A ∈ M
≡ ηH(A) (H(P )) by Lemma 2. By Lemma 1, there either exists a sub-
derivation of Γ `+ P(N ) =βη A, in which case by in-
≡ ηH(P(P )) (H(P ))
duction hypothesis H(Γ) `− H(P(N )) =β H(A) kind,
∗β H(P ) or P(N ) ≡ A, in which case H(Γ) `− H(P(N )) =β
H(A) kind by Proposition 1 Case 4 and Refl; fur-
by Lemma 5, since x 6∈ FV(H(C)) and x : C ∈ xA
thermore, in either case x 6∈ FV(H(A)) by Proposi-
implies C ≡ A by inversion.
tion 1 Case 1. Similarly, H(Γ) `− H(P([N/x]M )) =β
• y B . Then [H(P )/x]ηH(B) (y) ≡ η[H(P )/x]H(B) (y) ≡ H([N/x]B) and x 6∈ FV(H([N/x]B)).
ηH([P/x]B) (y), by Lemma 4 Case 2 since [H(P )/x]H(B)∗β Therefore, by Lemma 4 Cases 2 and 3 and Lemma 6:
H([P/x]B) by induction hypothesis.
H(AppB B
x:A (λx:A (M ), N ))
• λB
y:A (M ). Then, by definition, Lemma 4 Cases 1 and ≡ η[H(N )/x]H(B) (ηH(Πx:A.B) (λx.H(M ))(H(N )))
2 and induction hypothesis: ≡ η[H(N )/x]H(B) (λx.η[ηH(A) (x)/x]H(B) (
[H(P )/x]H(λB
y:A (M ))
(λx.H(M ))(ηH(A) (x)))(H(N )))
β η[H(N )/x]H(B) (η[ηH(A) (H(N ))/x]H(B) (
≡ [H(P )/x]ηΠy:H(A).H(B) (λy.H(M ))
(λx.H(M ))(ηH(A) (H(N )))))
≡ ηΠy:[H(P )/x]H(A).[H(P )/x]H(B) ([H(P )/x]λy.H(M )) ≡ η[H(N )/x]H(B) (η[ηH(P(N )) (H(N ))/x]H(B) (
≡ ηΠy:H([P/x]A).H([P/x]B) ([H(P )/x]λy.H(M )) (λx.H(M ))(ηH(P(N )) (H(N )))))
≡ ηΠy:H([P/x]A).H([P/x]B) (λy.[H(P )/x]H(M )) ∗β η[H(N )/x]H(B) (η[H(N )/x]H(B) (
∗β ηΠy:H([P/x]A).H([P/x]B) (λy.H([P/x]M )) (λx.H(M ))(H(N ))))
β η[H(N )/x]H(B) (η[H(N )/x]H(B) ([H(N )/x]H(M )))
[P/x]B
≡ H(λy:[P/x]A ([P/x]M )) ∗β η[H(N )/x]H(B) (H([N/x]M ))
≡ ηH([N/x]B) (H([N/x]M ))
≡ H([P/x](λB
y:A (M )))
≡ ηH(P([N/x]M )) (H([N/x]M ))
∗β H([N/x]M )
+
Definition 6. Define ηA (M ) by induction on A: • If N P then AppB
x:A (M, N ) Appx:A (M, P ).
B
+
βη M : A and M |βη| N then H(M )β
ηType (M ) = M Lemma 11. If Γ `+ +
+ H(N ).
ηEl(P ) (M ) = M
ηΠx:A.B (M ) = λB B A
x:A (Appx:A (M, x ))
Proof. By induction on M βη N , where the compatible
closure rules follow by induction hypothesis.
Define H + (M ) by induction on M :
x:C (λx:A (M ), N )) β
∗
For β, we need to show that H(AppD B
+ D B
H + (Type) = Type H([N/x]M ), where Γ `βη Appx:C (λx:A (M ), N ) : E. By in-
H + (El(P )) = El(H + (P )) version Γ `+ B
βη λx:A (M ) : Πx : A.B and Γ `
+
Πx : A.B =βη
H + (Πx : A.B) = Πx : H + (A).H + (B) −
Πx : C.D, so H(Γ) `β H(Πx : A.B) =βη H(Πx : C.D). By
+
H + (xA ) = ηH A
+ (A) (x ) Proposition 1 Case 7 and Church–Rosser H(A) =β H(C)
+ B and H(B) =β H(D), so:
H (λx:A (M )) =
+ H + (B)
+
ηΠx:H + (A).H + (B) (λx:H + (A) (H (M ))) H(AppD B B B
x:C (λx:A (M ), N )) ≡ H(Appx:A (λx:A (M ), N ))
+ B
H (Appx:A (M, N )) =
+ H + (B) + +
and the reduction sequence follows as for rule β in Sound-
η[H + (N )/x]H + (B) (Appx:H + (A) (H (M ), H (N ))) ness.
The reasoning for η-reduction is similar.
The H + (−) map extends to contexts in the obvious way.
The properties listed in Proposition 1 can now be shown
Lemma 9. |H + (M )| ≡ H(M ).
directly or transferred from the target language to the source
Proof. Induction on M . language.
Proposition 3. Definition 9. We define the type checking algorithm on
fully decorated terms Γ; A ⇒+ kind and Γ; P ⇒+ A induc-
1. If Γ `+
βη M : A then FV(M ) ∪ FV(A) ⊆ FV(Γ). tively as follows:
2. If Γ, Γ0 `+ + 0 • Γ; Type ⇒+ kind.
βη J, Γ `βη A kind and x 6∈ FV(Γ) ∪ FV(Γ )
0 +
then Γ, x : A, Γ `βη J. • Γ; El(M ) ⇒+ kind if Γ; M ⇒+ Type.
3. If Γ, x : A, Γ0 `+ + 0 +
βη J and Γ `βη N : A then Γ, [N/x]Γ `βη
• Γ; Πx : A.B ⇒+ kind if Γ; A ⇒+ kind and Γ, x :
[N/x]J. A; B ⇒+ kind.
• Γ; xC ⇒+ C if x : C ∈ Γ.
4. If Γ `+ +
βη M : A then Γ `βη A kind.
• Γ; λD
x:C (M ) ⇒
+
Πx : C.D0 if Γ; C ⇒+ kind, Γ, x :
5. If Γ `+ + +
βη M : A and Γ `βη M : B then Γ `βη A = C; D ⇒+ kind, Γ, x : C; M ⇒+ D0 and D =|βη| D0 .
B kind.
• Γ; AppD
x:C (M, N ) ⇒
+
[N/x]D0 if Γ; C ⇒+ kind, Γ, x :
6. If Γ `+ +
βη Πx : A.B =βη Πx : C.D kind then Γ `βη C; D ⇒+ kind, Γ; M ⇒+ Πx : C 0 .D0 , Γ; N ⇒+ C 00 ,
+
A =βη C kind and Γ, x : A `βη B =βη D kind. C =|βη| C 0 =|βη| C 00 and D =|βη| D0 .
Lemma 13.
βη M : A and M |βη| N then Γ `βη N : A.
7. If Γ `+ +
1. If Γ `+ +
βη A kind then Γ; A ⇒ kind.
8. If Γ `+
βη M : A then M is strongly normalizing under
βη . 2. If Γ `+ +
βη P : A then there is a C such that Γ; P ⇒ C
+
and Γ `βη A = C kind.
6. TYPE CHECKING Proof. By induction on derivations.
Given the full metatheory of `+βη developed above, the de- Finally, we define a second stripping operation strip(M )
cidability of type checking is similar to the standard treat-
that strips off the labels on variables and applications and
ment [19]. The novelty in our presentation in this section is
the codomain off of abstractions.
that we derive the fully decorated terms, using the standard
presentation of terms with no labels in variables or applica- Definition 10. Stripping from the fully decorated terms
tion and a single label for the domain in abstractions. to the standard presentation of lambda terms is defined as
follows:
Definition 8. We define the decorating type checking al-
gorithm Γ; A ⇒ B; kind and Γ; M ⇒ P ; A inductively as strip(xA ) = x
follows: strip(λB
x:A (M )) = λx : strip(A).strip(M )
• Γ; Type ⇒ Type; kind. strip(AppBx:A (M, N )) = strip(M )(strip(N ))
• Γ; El(M ) ⇒ El(P ); kind if Γ; M ⇒ P ; Type. Observe that if strip(M ) ≡ strip(N ) then |M | ≡ |N |, and
so Lemma 7 lifts to the map strip(−).
• Γ; Πx : A.B ⇒ Πx : C.D; kind if Γ; A ⇒ C; kind and
Lemma 14.
Γ, x : C; B ⇒ D; kind.
1. If Γ; A ⇒+ kind and strip(Γ) ≡ strip(Γ0 ) then there is
• Γ; x ⇒ xC ; C if x : C ∈ Γ. an A0 such that Γ; strip(A) ⇒ A0 ; kind and strip(A) ≡
strip(A0 ).
• Γ; λx : A.M ⇒ λD x:C (P ); Πx : C.D if Γ; A ⇒ C; kind
and Γ, x : C; M ⇒ P ; D. 2. If Γ; P ⇒+ C and strip(Γ) ≡ strip(Γ0 ) then there are
P 0 and C 0 such that Γ0 ; strip(P ) ⇒ P 0 ; C 0 , strip(C) ≡
• Γ; M (N ) ⇒ AppD
x:C (P, Q); [Q/x]D if Γ; M ⇒ P ; Πx : strip(C 0 ) and strip(P ) ≡ strip(P 0 ).
C.D, Γ; N ⇒ Q; C 0 and C =|βη| C 0 .
Proof. By induction on derivations.
Lemma 12 (Correctness of the Algorithm). We consider P ≡ AppD x:C (M, N ). By induction hypothesis
Γ0 ; strip(M ) ⇒ M 0 ; Πx : C 000 .D00 with strip(Πx : C 000 .D00 ) ≡
• If Γ; A ⇒ C; kind then Γ `+
βη C kind. strip(Πx : C 0 .D0 ), and strip(M ) ≡ strip(M 0 ) and Γ0 ; strip(N ) ⇒
N 0 ; C 0000 with strip(C 00 ) ≡ strip(C 0000 ) and strip(N ) ≡ strip(N 0 ).
• If Γ; M ⇒ P ; C then Γ `+
βη P : C. Furthermore, C 0000 =|βη| C 000 , since by assumption C 0 =|βη|
C 00 and by Correctness of the Algorithm, Lemma 7 and
Proof. By induction on derivations of Γ; A ⇒ C; kind
Proposition 1 Case 7 C 00 =|βη| C 0000 and C 000 =|βη| C 0 .
and Γ; M ⇒ P ; C, using Lemma 3 Case 4 and Completeness
Therefore:
for application.
strip([N/x]D0 ) ≡ strip([N 0 /x]D00 )
We now introduce a type checking algorithm directly on 00
0 0
fully decorated terms to show completeness of the algorithm. strip(AppD
x:C (M, N )) ≡ strip(AppD
x:C 000 (M , N ))
Γ `+ N : SA (M ) P(qB
x:A (M )) = [pB
x:A (M )/x]B
(out)
Γ `+ outA (N ) : A
The definitions of x : A ∈ B and x : A ∈ M extend
Γ `+ M : A trivially to the new term formers.
(out-∗)
Γ ` outA (∗A (M )) = M : A
+
Definition 12.
Γ `+ N : SA (M ) ηSA (M ) (N ) = ∗(M )
(∗-Uniq)
Γ `+ ∗A (M ) = N : SA (M ) ηΣx:A.B (M ) = pair(ηA (p(M )), η[p(M )/x]B (q(M )))
plus the obvious compatible closure rules for kind and term
Definition 13.
formers S, ∗ and out.
For the unlabeled system, the term formers ∗(M ) and H(∗A (M )) = ∗(H(M ))
out(M ) have no labels. H(outA (M )) = ηH(A) (out(H(M )))
7.2 Dependent Pairs H(pairB
x:A (M, N )) = ηH(Σx:A.B) (pair(H(M ), H(N )))
H(pB x:A (M )) = ηH(A) (p(H(M )))
Γ `+ A kind Γ, x : A `+ B kind H(qB
(Σ) x:A (M )) = η[H(pB (M ))/x]H(B) (q(H(M )))
x:A
Γ ` Σx : A.B kind
+