HAL Id: hal-00382691
https://hal.archives-ouvertes.fr/hal-00382691
Submitted on 11 May 2009
HAL is a multi-disciplinary open access archive for the deposit and dissemination of sci- entific research documents, whether they are pub- lished or not. The documents may come from teaching and research institutions in France or abroad, or from public or private research centers.
L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des établissements d’enseignement et de recherche français ou étrangers, des laboratoires publics ou privés.
A complete realisability semantics for intersection types and arbitrary expansion variables
Fairouz Kamareddine, Karim Nour, Vincent Rahli, J. B. Wells
To cite this version:
Fairouz Kamareddine, Karim Nour, Vincent Rahli, J. B. Wells. A complete realisability semantics for intersection types and arbitrary expansion variables. 5th International Colloquium on Theoretical Aspects of Computing, ICTAC 2008, 1-3 September 2008, Sep 2008, Istanbul, Turkey. pp.171-185.
�hal-00382691�
intersection types and arbitrary expansion variables
Fairouz Kamareddine
1, Karim Nour
2, Vincent Rahli
1, and J. B. Wells
11
ULTRA Group (Useful Logics, Types, Rewriting, and their Automation),
http://www.macs.hw.ac.uk/ultra/2
Universit´e de Savoie, Campus Scientifique, 73378 Le Bourget du Lac, France,
nour@univ-savoie.frAbstract.
Expansion was introduced at the end of the 1970s for calcu- lating principal typings for
λ-terms in intersection type systems.Expan- sion variables (E-variables) were introduced at the end of the 1990s to simplify and help mechanise expansion. Recently, E-variables have been further simplified and generalised to also allow calculating other type operators than just intersection. There has been much work on seman- tics for intersection type systems, but only one such work on intersection type systems with E-variables. That work established that building a se- mantics for E-variables is very challenging. Because it is unclear how to devise a space of meanings for E-variables, that work developed instead a space of meanings for types that is hierarchical in the sense of hav- ing many degrees (denoted by indexes). However, although the indexed calculus helped identify the serious problems of giving a semantics for expansion variables, the sound realisability semantics was only complete when one single E-variable is used and furthermore, the universal type
ωwas not allowed. In this paper, we are able to overcome these challenges.
We develop a realisability semantics where we allow an arbitrary (possi- bly infinite) number of expansion variables and where
ωis present. We show the soundness and completeness of our proposed semantics.
1 Introduction
Expansion is a crucial part of a procedure for calculating principal typings and
thus helps support compositional type inference. For example, the λ-term M =
(λx.x(λy.yz)) can be assigned the typing Φ
1= h(z : a) ⊢ (((a →b)→ b) →c)→ ci,
which happens to be its principal typing. The term M can also be assigned the
typing Φ
2= h(z : a
1⊓ a
2) ⊢ (((a
1→ b
1) → b
1) ⊓ ((a
2→ b
2) → b
2) → c) → ci, and
an expansion operation can obtain Φ
2from Φ
1. Because the early definitions of
expansion were complicated [4], E-variables were introduced in order to make the
calculations easier to mechanise and reason about. For example, in System E [2],
the above typing Φ
1is replaced by Φ
3= h(z : ea) ⊢ e((((a → b) → b) → c) → c)i,
which differs from Φ
1by the insertion of the E-variable e at two places, and Φ
2can be obtained from Φ
3by substituting for e the expansion term:
E = (a := a
1, b := b
1) ⊓ (a := a
2, b := b
2).
Carlier and Wells [3] have surveyed the history of expansion and also E- variables. Kamareddine, Nour, Rahli and Wells [13] showed that E-variables pose serious challenges for semantics. In the list of open problems published in 1975 in [6], it is suggested that an arrow type expresses functionality. Following this idea, a type’s semantics is given as a set of closed λ-terms with behaviour related to the specification given by the type. In many kinds of semantics, the meaning of a type T is calculated by an expression [T ]
νthat takes two parameters, the type T and a valuation ν that assigns to type variables the same kind of meanings that are assigned to types. In that way, models based on term-models have been built for intersection type systems [7,14,11] where intersection types (introduced to type more terms than in the Simply Typed Lambda Calculus) are interpreted by set-theoretical intersection of meanings. To extend this idea to types with E-variables, we need to devise some space of possible meanings for E-variables.
Given that a type e T can be turned by expansion into a new type S
1(T ) ⊓ S
2(T ), where S
1and S
2are arbitrary substitutions (or even arbitrary further expansions), and that this can introduce an unbounded number of new variables (both E-variables and regular type variables), the situation is complicated.
This was the main motivation for [13] to develop a space of meanings for types that is hierarchical in the sense of having many degrees. When assigning meanings to types, [13] captured accurately the intuition behind E-variables by ensuring that each use of E-variables simply changes degrees and that each E- variable acts as a kind of capsule that isolates parts of the λ-term being analysed by the typing.
The semantic approach used in [13] is realisability semantics along the lines in Coquand [5] and Kamareddine and Nour [11]. Realisability allows showing soundness in the sense that the meaning of a type T contains all closed λ- terms that can be assigned T as their result type. This has been shown useful in previous work for characterising the behaviour of typed λ-terms [14]. One also wants to show the converse of soundness which is called completeness (see Hindley [8,9,10]), i.e., that every closed λ-term in the meaning of T can be assigned T as its result type. Moreover, [13] showed that if more than one E- variable is used, the semantics is not complete. Furthermore, the degrees used in [13] made it difficult to allow the universal type ω and this limited the study to the λI-calculus. In this paper, we are able to overcome these challenges. We develop a realisability semantics where we allow the full λ-calculus, an arbitrary (possibly infinite) number of expansion variables and where ω is present, and we show its soundness and completeness. We do so by introducing an indexed calculus as in [13]. However here, our indices are finite sequences of natural numbers rather than single natural numbers.
In Section 2 we give the full λ-calculus indexed with finite sequences of nat-
ural numbers and show the confluence of β , βη and weak head reduction on the
indexed λ-calculus. In Section 3 we introduce the type system for the indexed λ-
calculus (with the universal type ω). In this system, intersections and expansions
cannot occur directly to the right of an arrow. In Section 4 we establish that subject reduction holds for ⊢. In Section 5 we show that subject β-expansion holds for ⊢ but that subject η-expansion fails. In Section 6 we introduce the realisability semantics and show its soundness for ⊢. In Section 7 we establish the completeness of ⊢ by introducing a special interpretation. We conclude in Section 8. Due to space limitations, we omit the details of the proofs. Full proofs however can be found in the expanded version of this article (currently at [12]) which will always be available at the authors’ web pages.
2 The pure λ
LN-calculus
In this section we give the λ-calculus indexed with finite sequences of natural numbers and show the confluence of β, βη and weak head reduction.
Let n, m, i, j, k, l be metavariables which range over the set of natural num- bers N = {0, 1, 2, . . .}. We assume that if a metavariable v ranges over a set s then v
iand v
′, v
′′, etc. also range over s. A binary relation is a set of pairs. Let rel range over binary relations. We sometimes write x rel y instead of hx, yi ∈ rel . Let dom(rel ) = {x / hx, yi ∈ rel } and ran(rel) = {y / hx, yi ∈ rel }. A function is a binary relation fun such that if {hx, yi, hx, zi} ⊆ fun then y = z. Let fun range over functions. Let s → s
′= {fun / dom(fun) ⊆ s ∧ ran(fun) ⊆ s
′}. We sometimes write x : s instead of x ∈ s.
First, we introduce the set L
Nof indexes with an order relation on indexes.
Definition 1. 1. An index is a finite sequence of natural numbers L = (n
i)
1≤i≤l. We denote L
Nthe set of indexes and ⊘ the empty sequence of natural num- bers. We let L, K, R range over L
N.
2. If L = (n
i)
1≤i≤land m ∈ N , we use m :: L to denote the sequence (r
i)
1≤i≤l+1where r
1= m and for all i ∈ {2, . . . , l + 1}, r
i= n
i−1. In particular, k :: ⊘ = (k).
3. If L = (n
i)
1≤i≤nand K = (m
i)
1≤i≤m, we use L :: K to denote the sequence (r
i)
1≤i≤n+mwhere for all i ∈ {1, . . . , n}, r
i= n
iand for all i ∈ {n + 1, . . . , n + m}, r
i= m
i−n. In particular, L :: ⊘ = ⊘ :: L = L.
4. We define on L
Na binary relation by:
L
1L
2(or L
2L
1) if there exists L
3∈ L
Nsuch that L
2= L
1:: L
3. Lemma 1. is an order relation on L
N.
The next definition gives the syntax of the indexed calculus and the notions of reduction.
Definition 2. 1. Let V be a countably infinite set of variables. The set of terms M, the set of free variables fv(M ) of a term M ∈ M, the degree function d : M → L
Nand the joinability M ⋄ N of terms M and N are defined by simultaneous induction as follows:
– If x ∈ V and L ∈ L
N, then x
L∈ M, fv(x
L) = {x
L} and d(x
L) = L.
– If M, N ∈ M, d(M ) d(N ) and M ⋄ N (see below), then M N ∈ M,
fv(M N ) = fv(M ) ∪ fv(N ) and d(M N ) = d(M ).
– If x ∈ V, M ∈ M and L d(M ), then λx
L.M ∈ M, fv(λx
L.M) = fv(M ) \ {x
L} and d(λx
L.M) = d(M ).
2. – Let M, N ∈ M. We say that M and N are joinable and write M ⋄ N iff for all x ∈ V , if x
L∈ fv(M ) and x
K∈ fv(N ), then L = K.
– If X ⊆ M such that for all M, N ∈ X , M ⋄ N , we write, ⋄X .
– If X ⊆ M and M ∈ M such that for all N ∈ X , M ⋄ N, we write, M ⋄X . The ⋄ property ensures that in any term M , variables have unique degrees.
We assume the usual definition of subterms and the usual convention for parentheses and their omission (see Barendregt [1] and Krivine [14]). Note that every subterm of M ∈ M is also in M. We let x, y, z, etc. range over V and M, N, P range over M and use = for syntactic equality.
3. The usual simultaneous substitution M [(x
Lii:= N
i)
n] of N
i∈ M for all free occurrences of x
Liiin M ∈ M is only defined when ⋄{M } ∪ {N
i/ i ∈ {1, . . . , n}} and for all i ∈ {1, . . . , n}, d(N
i) = L
i. In a substitution, we sometimes write x
L11:= N
1, . . . , x
Lnn:= N
ninstead of (x
Lii:= N
i)
n. We sometimes write M [(x
Lii:= N
i)
1as M [x
L11:= N
1].
4. We take terms modulo α-conversion given by:
λx
L.M = λy
L.(M [x
L:= y
L]) where for all L, y
L6∈ fv(M ).
Moreover, we use the Barendregt convention (BC) where the names of bound variables differ from the free ones and where we rewrite terms so that not both λx
Land λx
Kco-occur when L 6= K.
5. A relation rel on M is compatible iff for all M, N, P ∈ M:
– If M rel N and λx
L.M, λx
L.M ∈ M then (λx
L.M) rel (λx
L.N ).
– If M rel N and M P, N P ∈ M (resp. P M, P N ∈ M), then (M P) rel (N P ) (resp. (P M ) rel (P N)).
6. The reduction relation ⊲
βon M is defined as the least compatible relation closed under the rule: (λx
L.M)N ⊲
βM [x
L:= N ] if d(N ) = L
7. The reduction relation ⊲
ηon M is defined as the least compatible relation closed under the rule: λx
L.(M x
L) ⊲
ηM if x
L6∈ fv(M )
8. The weak head reduction ⊲
hon M is defined by:
(λx
L.M)N N
1. . . N
n⊲
hM [x
L:= N ]N
1. . . N
nwhere n ≥ 0
9. We let ⊲
βη= ⊲
β∪ ⊲
η. For r ∈ {β, η, h, βη}, we denote by ⊲
∗rthe reflexive and transitive closure of ⊲
rand by ≃
rthe equivalence relation induced by
⊲
∗r.
The next theorem whose proof can be found in [12] states that free variables and degrees are preserved by our notions of reduction.
Theorem 1. Let M ∈ M and r ∈ {β, βη, h}.
1. If M ⊲
∗ηN then fv(N ) = fv(M ) and d(M ) = d(N ).
2. If M ⊲
∗rN then fv(N ) ⊆ fv(M ) and d(M ) = d(N ).
As expansions change the degree of a term, indexes in a term need to in- crease/decrease.
Definition 3. Let i ∈ N and M ∈ M.
1. We define M
+iby:
•(x
L)
+i= x
i::L•(M
1M
2)
+i= M
1+iM
2+i•(λx
L.M)
+i= λx
i::L.M
+iLet M
+⊘= M and M
+(i::L)= (M
+i)
+L.
2. If d(M ) = i :: L, we define M
−iby:
•(x
i::K)
−i= x
K•(M
1M
2)
−i= M
1−iM
2−i•(λx
i::K.M)
−i= λx
K.M
−iLet M
−⊘= M and if d(M ) i :: L then M
−(i::L)= (M
−i)
−L. 3. Let X ⊆ M. We write X
+ifor {M
+i/ M ∈ X }.
Normal forms are defined as usual.
Definition 4. 1. M ∈ M is in β-normal form (βη-normal form, h-normal form resp.) if there is no N ∈ M such that M ⊲
βN (M ⊲
βηN , M ⊲
hN resp.).
2. M ∈ M is β-normalising (βη-normalising, h-normalising resp.) if there is an N ∈ M such that M ⊲
∗βN (M ⊲
βηN, M ⊲
hN resp.) and N is in β-normal form (βη-normal form, h-normal form resp.).
The next theorem states that all of our notions of reduction are confluent on our indexed calculus. For a proof see [12].
Theorem 2 (Confluence). Let M, M
1, M
2∈ M and r ∈ {β, βη, h}.
1. If M ⊲
∗rM
1and M ⊲
∗rM
2, then there is M
′such that M
1⊲
∗rM
′and M
2⊲
∗rM
′. 2. M
1≃
rM
2iff there is a term M such that M
1⊲
∗rM and M
2⊲
∗rM .
3 Typing system
This paper studies a type system for the indexed λ-calculus with the universal type ω. In this type system, in order to get subject reduction and hence com- pleteness, intersections and expansions cannot occur directly to the right of an arrow (see U below).
The next two definitions introduce the type system.
Definition 5. 1. Let a range over a countably infinite set A of atomic types and let e range over a countably infinite set E = {e
0, e
1, ...} of expansion variables. We define sets of types T and U , such that T ⊆ U , and a function d : U → L
Nby:
– If a ∈ A, then a ∈ T and d(a) = ⊘.
– If U ∈ U and T ∈ T , then U → T ∈ T and d(U → T ) = ⊘.
– If L ∈ L
N, then ω
L∈ U and d(ω
L) = L.
– If U
1, U
2∈ U and d(U
1) = d(U
2), then U
1⊓ U
2∈ U and d(U
1⊓ U
2) = d(U
1) = d(U
2).
– U ∈ U and e
i∈ E , then e
iU ∈ U and d(e
iU ) = i :: d(U ).
Note that d remembers the number of the expansion variables e
iin order to keep a trace of these variables.
We let T range over T , and U, V, W range over U . We quotient types by
taking ⊓ to be commutative (i.e. U
1⊓ U
2= U
2⊓ U
1), associative (i.e. U
1⊓
(U
2⊓U
3) = (U
1⊓U
2)⊓U
3) and idempotent (i.e. U ⊓U = U ), by assuming the distributivity of expansion variables over ⊓ (i.e. e(U
1⊓U
2) = eU
1⊓ eU
2) and by having ω
Las a neutral (i.e. ω
L⊓ U = U ). We denote U
n⊓ U
n+1. . . ⊓ U
mby ⊓
mi=nU
i(when n ≤ m). We also assume that for all i ≥ 0 and K ∈ L
N, e
iω
K= ω
i::K.
2. We denote e
i1. . . e
inby e
K, where K = (i
1, . . . , i
n) and U
n⊓ U
n+1. . . ⊓ U
mby ⊓
mi=nU
i(when n ≤ m).
Definition 6. 1. A type environment is a set {x
L11: U
1, . . . , x
Lnn: U
n} such that for all i, j ∈ {1, . . . , n}, if x
Lii= x
Ljjthen U
i= U
j}. We let Env be the set of environments, use Γ, ∆ to range over Env and write () for the empty environment. We define dom(Γ ) = {x
L/ x
L: U ∈ Γ }. If dom(Γ
1) ∩ dom(Γ
2) = ∅, we write Γ
1, Γ
2for Γ
1∪ Γ
2. We write Γ, x
L: U for Γ, {x
L: U } and x
L: U for {x
L: U }. We denote x
L11: U
1, . . . , x
Lnn: U
nby (x
Lii: U
i)
n. 2. If M ∈ M and fv(M ) = {x
L11, . . . , x
Lnn}, we denote env
Mωthe type environ-
ment (x
Lii: ω
Li)
n.
3. We say that a type environment Γ is OK (and write OK(Γ )) iff for all x
L: U ∈ Γ , d(U ) = L.
4. Let Γ
1= (x
Lii: U
i)
n, Γ
1′and Γ
2= (x
Lii: U
i′)
n, Γ
2′such that dom(Γ
1′) ∩ dom(Γ
2′) = ∅ and for all i ∈ {1, . . . , n}, d(U
i) = d(U
i′). We denote Γ
1⊓ Γ
2the type environment (x
Lii: U
i⊓ U
i′)
n, Γ
1′, Γ
2′. Note that Γ
1⊓ Γ
2is a type environment, dom(Γ
1⊓Γ
2) = dom(Γ
1)∪dom(Γ
2) and that, on environments,
⊓ is commutative, associative and idempotent.
5. Let Γ = (x
Lii: U
i)
1≤i≤nWe denote e
jΓ = (x
j::Li i: e
jU
i)
1≤i≤n. Note that eΓ is a type environment and e(G
1⊓ Γ
2) = eΓ
1⊓ eΓ
2. 6. We write Γ
1⋄ Γ
2iff x
L∈ dom(Γ
1) and x
K∈ dom(Γ
2) implies K = L.
7. We follow [3] and write type judgements as M : hΓ ⊢ U i instead of the tradi- tional format of Γ ⊢ M : U , where ⊢ is our typing relation. The typing rules of ⊢ are given on the left hand side of Figure 7. In the last clause, the binary relation ⊑ is defined on U by the rules on the right hand side of Figure 7.
We let Φ denote types in U , or environments Γ or typings hΓ ⊢ U i. When Φ ⊑ Φ
′, then Φ and Φ
′belong to the same set ( U /environments/typings).
8. If L ∈ L
N, U ∈ U and Γ = (x
Lii: U
i)
nis a type environment, we say that:
– d(Γ ) L if and only if for all i ∈ {1, . . . , n}, d(U
i) L and L
iL.
– d(hΓ ⊢ U i) L if and only if d(Γ ) L and d(U ) L.
To illustrate how our indexed type system works, we give an example:
Example 1. Let U = e
3(e
2(e
1((e
0b → c) → (e
0(a ⊓ (a → b)) → c)) → d) → (((e
2d → a) ⊓ b) → a)) where a, b, c, d ∈ A,
L
1= 3 :: ⊘ L
2= 3 :: 2 :: ⊘ L
3= 3 :: 2 :: 1 :: 0 :: ⊘ and
M = λx
L2.λy
L1.(y
L1(x
L2λu
L3.λv
L3.(u
L3(v
L3v
L3)))).
We invite the reader to check that M : h() ⊢ U i.
Just as we did for terms, we decrease the indexes of types, environments and
typings.
x⊘
:
h(x⊘:
T)
⊢Ti(ax)
M
:
henvMω ⊢ωd
(M)i(ω)
M
:
hΓ,(x
L:
U)
⊢Ti λxL.M:
hΓ ⊢U→Ti(→
I)
M
:
hΓ ⊢Ti xL6∈dom(Γ )
λxL.M:
hΓ ⊢ωL→Ti(→
′I)
M1
:
hΓ1⊢U →Ti M2:
hΓ2⊢Ui Γ1⋄Γ2M1M2
:
hΓ1⊓Γ2⊢Ti(→
E)
M
:
hΓ ⊢U1i M:
hΓ ⊢U2i M:
hΓ ⊢U1⊓U2i(⊓
I)
M
:
hΓ ⊢Ui M+j:
hejΓ ⊢ejUi(e)
M
:
hΓ ⊢Ui hΓ ⊢Ui ⊑ hΓ′⊢U′i M:
hΓ′⊢U′i(⊑)
Φ⊑Φ
(ref )
Φ1⊑Φ2 Φ2⊑Φ3
Φ1⊑Φ3
(tr)
d(U1
) =
d(U2)
U1⊓U2⊑U1(⊓
E)
U1⊑V1 U2⊑V2
U1⊓U2⊑V1⊓V2
(⊓)
U2⊑U1 T1⊑T2
U1→T1⊑U2→T2
(→)
U1⊑U2 eU1⊑eU2
(⊑
e)
U1⊑U2
Γ, yL
:
U1⊑Γ, yL:
U2(⊑
c)
U1⊑U2 Γ2⊑Γ1
hΓ1⊢U1i ⊑ hΓ2⊢U2i
(⊑
hi)
Fig. 1. Typing rules / Subtyping rules
Definition 7. 1. If d(U ) L, then if L = ⊘ then U
−L= U else L = i :: K and we inductively define the type U
−Las follows:
(U
1⊓ U
2)
−i::K= U
1−i::K⊓ U
2−i::K(e
iU )
−i::K= U
−KWe write U
−iinstead of U
−(i).
2. If Γ = (x
Lii: U
i)
kand d(Γ ) L, then for all i ∈ {1, . . . , k}, L
i= L :: L
′iand d(U
i) L and we denote Γ
−L= (x
L′i: U
i−L)
k.
We write Γ
−iinstead of Γ
−(i).
3. If U is a type and Γ is a type environment such that d(Γ ) K and d(U ) K, then we denote (hΓ ⊢ U i)
−K= hΓ
−K⊢ U
−Ki.
The next lemma is informative about types and their degrees.
Lemma 2. 1. If T ∈ T , then d(T ) = ⊘.
2. Let U ∈ U . If d(U ) = L = (n
i)
m, then U = ω
Lor U = e
L⊓
pi=1T
iwhere p ≥ 1 and for all i ∈ {1, . . . , p}, T
i∈ T .
3. Let U
1⊑ U
2. (a) d(U
1) = d(U
2).
(b) If U
1= ω
Kthen U
2= ω
K.
(c) If U
1= e
KU then U
2= e
KU
′and U ⊑ U
′.
(d) If U
2= e
KU then U
1= e
KU
′and U ⊑ U
′.
(e) If U
1= ⊓
pi=1e
K(U
i→ T
i) where p ≥ 1 then U
2= ω
Kor U
2=
⊓
qj=1e
K(U
j′→ T
j′) where q ≥ 1 and for all j ∈ {1, . . . , q}, there exists i ∈ {1, . . . , p} such that U
j′⊑ U
iand T
i⊑ T
j′.
4. If U ∈ U such that d(U ) = L then U ⊑ ω
L.
5. If U ⊑ U
1′⊓ U
2′then U = U
1⊓ U
2where U
1⊑ U
1′and U
2⊑ U
2′. 6. If Γ ⊑ Γ
1′⊓ Γ
2′then Γ = Γ
1⊓ Γ
2where Γ
1⊑ Γ
1′and Γ
2⊑ Γ
2′.
The next lemma says how ordering or the decreasing of indexes propagate to environments.
Lemma 3. 1. OK(env
ωM).
2. If Γ ⊑ Γ
′, U ⊑ U
′and x
L6∈ dom(Γ ) then Γ, (x
L: U ) ⊑ Γ
′, (x
L: U
′).
3. Γ ⊑ Γ
′iff Γ = (x
Lii: U
i)
n, Γ
′= (x
Lii: U
i′)
nand for every 1 ≤ i ≤ n, U
i⊑ U
i′.
4. hΓ ⊢ U i ⊑ hΓ
′⊢ U
′i iff Γ
′⊑ Γ and U ⊑ U
′. 5. If dom(Γ ) = fv(M ) and OK(Γ ) then Γ ⊑ env
Mω6. If Γ ⋄ ∆ and d(Γ ), d(∆) K, then Γ
−K⋄ ∆
−K. 7. If U ⊑ U
′and d(U ) K then U
−K⊑ U
′−K. 8. If Γ ⊑ Γ
′and d(Γ ) K then Γ
−K⊑ Γ
′−K. 9. If OK(Γ
1), OK(Γ
2) then OK(Γ
1⊓ Γ
2).
10. If OK(Γ ) then OK(eΓ ).
11. If Γ
1⊑ Γ
2then (d(Γ
1) L iff d(Γ
2) L) and (OK(Γ
1) iff OK(Γ
2)).
The next lemma shows that we do not allow weakening in ⊢.
Lemma 4. 1. For every Γ and M such that OK(Γ ) dom(Γ ) = fv(M ) and d(M ) = K, we have M : hΓ ⊢ ω
Ki.
2. If M : hΓ ⊢ U i, then dom(Γ ) = fv(M ).
3. If M
1: hΓ
1⊢ U i and M
2: hΓ
2⊢ V i then Γ
1⋄ Γ
2iff M
1⋄ M
2.
Proof. 1. By ω, M : henv
ωM⊢ ω
Ki. By Lemma 3.5, Γ ⊑ env
ωM. Hence, by ⊑ and
⊑
hi, M : hΓ ⊢ ω
Ki.
2. By induction on the derivation M : hΓ ⊢ U i.
3. If) Let x
L∈ dom(Γ
1) and x
K∈ dom(Γ
2) then by Lemma 4.2, x
L∈ fv(M
1) and x
K∈ fv(M
2) so Γ
1⋄ Γ
2. Only if) Let x
L∈ fv(M
1) and x
K∈ fv(M
2) then by Lemma 4.2, x
L∈ dom(Γ
1) and x
K∈ dom(Γ
2) so M
1⋄ M
2. The next theorem states that typings are well defined and that within a typing, degrees are well behaved.
Theorem 3. 1. The typing relation ⊢ is well defined on M × Env × U . 2. If M : hΓ ⊢ U i then OK(Γ ), and d(Γ ) d(U) = d(M ).
3. If M : hΓ ⊢ U i and d(U ) K then M
−K: hΓ
−K⊢ U
−Ki.
Proof. We prove 1. and 2. simultaneously by induction on the derivation M : hΓ ⊢ U i. We prove 3. by induction on the derivation M : hΓ ⊢ U i. Full details
can be found in [12].
Finally, here are two derivable typing rules that we will freely use in the rest
of the article.
Remark 1. 1. The rule M : hΓ
1⊢ U
1i M : hΓ
2⊢ U
2i
M : hΓ
1⊓ Γ
2⊢ U
1⊓ U
2i ⊓
′Iis derivable.
2. The rule
x d
(U): h(x d
(U): U ) ⊢ U i ax
′is derivable.
4 Subject reduction properties
In this section we show that subject reduction holds for ⊢. The proof of subject reduction uses generation and substitution. Hence the next two lemmas.
Lemma 5 (Generation for ⊢).
1. If x
L: hΓ ⊢ Ui, then Γ = (x
L: V ) and V ⊑ U .
2. If λx
L.M : hΓ ⊢ U i, x
L∈ fv(M ) and d(U) = K, then U = ω
Kor U =
⊓
pi=1e
K(V
i→ T
i) where p ≥ 1 and for all i ∈ {1, . . . , p}, M : hΓ, x
L: e
KV
i⊢ e
KT
ii.
3. If λx
L.M : hΓ ⊢ U i, x
L6∈ fv(M ) and d(U) = K, then U = ω
Kor U =
⊓
pi=1e
K(V
i→ T
i) where p ≥ 1 and for all i ∈ {1, . . . , p}, M : hΓ ⊢ e
KT
ii.
4. If M x
L: hΓ, (x
L: U ) ⊢ T i and x
L6∈ fv(M ), then M : hΓ ⊢ U → T i.
Lemma 6 (Substitution for ⊢). If M : hΓ, x
L: U ⊢ V i, N : h∆ ⊢ U i and M ⋄ N then M [x
L:= N ] : hΓ ⊓ ∆ ⊢ V i.
Since ⊢ does not allow weakening, we need the next definition since when a term is reduced, it may lose some of its free variables and hence will need to be typed in a smaller environment.
Definition 8. If Γ is a type environment and U ⊆ dom(Γ ), then we write Γ ↾
Ufor the restriction of Γ on the variables of U . If U = fv(M ) for a term M , we write Γ ↾
Minstead of Γ ↾ fv
(M).
Now we are ready to prove the main result of this section:
Theorem 4 (Subject reduction for ⊢). If M : hΓ ⊢ U i and M ⊲
∗βηN , then N : hΓ ↾
N⊢ U i.
Proof. By induction on the length of the derivation M ⊲
∗βηN . Case M ⊲
βηN
is by induction on the derivation M : hΓ ⊢
3U i.
Corollary 1. 1. If M : hΓ ⊢ Ui and M ⊲
∗βN , then N : hΓ ↾
N⊢ U i.
2. If M : hΓ ⊢ U i and M ⊲
∗hN , then N : hΓ ↾
N⊢ U i.
5 Subject expansion properties
In this section we show that subject β-expansion holds for ⊢ but that subject η-expansion fails.
The next lemma is needed for expansion.
Lemma 7. If M [x
L:= N ] : hΓ ⊢ U i and x
L∈ fv(M ) then there exist a type V and two type environments Γ
1, Γ
2such that:
M : hΓ
1, x
L: V ⊢ U i N : hΓ
2⊢ V i Γ = Γ
1⊓ Γ
2Since more free variables might appear in the β-expansion of a term, the next definition gives a possible enlargement of an environment.
Definition 9. Let m ≥ n, Γ = (x
Lii: U
i)
nand U = {x
L11, ..., x
Lmm}. We write Γ ↑
Ufor x
L11: U
1, ..., x
Lnn: U
n, x
Ln+1n+1: ω
Ln+1, ..., x
Lmm: ω
Lm. Note that Γ ↑
Uis a type environment. If dom(Γ ) ⊆ fv(M ), we write Γ ↑
Minstead of Γ ↑ fv
(M).
We are now ready to establish that subject expansion holds for β (next theorem) and that it fails for η (Lemma 8).
Theorem 5 (Subject expansion for β). If N : hΓ ⊢ U i and M ⊲
∗βN , then M : hΓ ↑
M⊢ U i.
Proof. By induction on the length of the derivation M ⊲
∗βN using the fact that
if fv(P ) ⊆ fv(Q), then (Γ ↑
P)↑
Q= Γ ↑
Q.
Corollary 2. If N : hΓ ⊢ U i and M ⊲
∗hN, then M : hΓ ↑
M⊢ Ui.
Lemma 8 (Subject expansion fails for η). Let a be an element of A. We have:
1. λy
⊘.λx
⊘.y
⊘x
⊘⊲
ηλy
⊘.y
⊘2. λy
⊘.y
⊘: h() ⊢ a → ai.
3. It is not possible that
λy
⊘.λx
⊘.y
⊘x
⊘: h() ⊢ a → ai.
Hence, the subject η-expansion lemmas fail for ⊢.
Proof. 1. and 2. are easy. For 3., assume λy
⊘.λx
⊘.y
⊘x
⊘: h() ⊢ a → ai.
By Lemma 5.2, λx
⊘.y
⊘x
⊘: h(y : a) ⊢→ ai. Again, by Lemma 5.2, a = ω
⊘or there exists n ≥ 1 such that a = ⊓
ni=1(U
i→ T
i), absurd.
6 The realisability semantics
In this section we introduce the realisability semantics and show its soundness for ⊢.
Crucial to a realisability semantics is the notion of a saturated set:
Definition 10. Let X, Y ⊆ M.
1. We use P (X ) to denote the powerset of X , i.e. {Y / Y ⊆ X }.
2. We define X
+i= {M
+i/ M ∈ X }.
3. We define X Y = {M ∈ M / M N ∈ Y for all N ∈ X such that M ⋄ N }.
4. We say that X ≀ Y iff for all M ∈ X Y, there exists N ∈ X such that
M ⋄ N.
5. For r ∈ {β, βη, h}, we say that X is r-saturated if whenever M ⊲
∗rN and N ∈ X , then M ∈ X .
Saturation is closed under intersection, lifting and arrows:
Lemma 9. 1. (X ∩ Y)
+i= X
+i∩ Y
+i.
2. If X , Y are r-saturated sets, then X ∩ Y is r-saturated.
3. If X is r-saturated, then X
+iis r-saturated.
4. If Y is r-saturated, then, for every set X , X Y is r-saturated.
5. (X Y )
+i⊆ X
+iY
+i.
6. If X
+i≀ Y
+i, then X
+iY
+i⊆ (X Y)
+i.
We now give the basic step in our realisability semantics: the interpretations and meanings of types.
Definition 11. Let V
1, V
2be countably infinite, V
1∩ V
2= ∅ and V = V
1∪ V
2. 1. Let L ∈ L
N. We define M
L= {M ∈ M / d(M ) = L}.
2. Let x ∈ V
1. We define N
xL= {x
LN
1...N
k∈ M / k ≥ 0}.
3. Let r ∈ {β, βη, h}. An r-interpretation I : A 7→ P(M
⊘) is a function such that for all a ∈ A:
• I(a) is r-saturated and • ∀x ∈ V
1. N
x⊘⊆ I(a).
We extend an r-interpretation I to U as follows:
• I(ω
L) = M
L• I(e
iU ) = I(U )
+i• I(U
1⊓ U
2) = I(U
1) ∩ I(U
2) • I(U → T ) = I(U ) I(T ) Let r-int = {I / I is an r-interpretation}.
4. Let U ∈ U and r ∈ {β, βη, h}. Define [U]
r, the r-interpretation of U by:
[U ]
r= {M ∈ M / M is closed and M ∈ T
I∈r
-int I(U )}
Lemma 10. Let r ∈ {β, βη, h}.
1. (a) For any U ∈ U and I ∈ r-int, we have I(U ) is r-saturated.
(b) If d(U ) = L and I ∈ r-int, then for all x ∈ V
1, N
xL⊆ I(U ) ⊆ M
L. 2. Let r ∈ {β, βη, h}. If I ∈ r-int and U ⊑ V , then I(U ) ⊆ I(V ).
Here is the soundness lemma.
Lemma 11 (Soundness). Let r ∈ {β, βη, h}, M : h(x
Ljj: U
j)
n⊢ U i, I ∈ r-int and for all j ∈ {1, . . . , n}, N
j∈ I(U
j). If M [(x
Ljj:= N
j)
n] ∈ M then M [(x
Ljj:=
N
j)
n] ∈ I(U ).
Proof. By induction on the derivation M : h(x
Ljj: U
j)
n⊢ U i.
Corollary 3. Let r ∈ {β, βη, h}. If M : h() ⊢ U i, then M ∈ [U ]
r. Proof. By Lemma 11, M ∈ I(U ) for any r-interpretation I . By Lemma 4.2, fv(M ) = dom(()) = ∅ and hence M is closed. Therefore, M ∈ [U ]
r. Lemma 12 (The meaning of types is closed under type operations).
Let r ∈ {β, βη, h}. On U , the following hold:
1. [e
iU ]
r= [U ]
+ir2. [U ⊓ V ]
r= [U ]
r∩ [V ]
r3. If I ∈ r-int and U, V ∈ U , then I(U) ≀ I(V ).
Proof. 1. and 2. are easy. 3. Let d(U ) = K, M ∈ I (U ) I (V ) and x ∈ V
1such that for all L, x
L6∈ fv(M ), then M ⋄ x
Kand by lemma 10.1b, x
K∈ I (U ).
The next definition and lemma put the realisability semantics in use.
Definition 12 (Examples). Let a, b ∈ A where a 6= b. We define:
– Id
0= a → a, Id
1= e
1(a → a) and Id
′1= e
1a → e
1a.
– D = (a ⊓ (a → b)) → b.
– N at
0= (a → a) → (a → a), N at
1= e
1((a → a) → (a → a)), and N at
′0= (e
1a → a) → (e
1a → a).
Moreover, if M, N are terms and n ∈ N , we define (M )
nN by induction on n:
(M )
0N = N and (M )
m+1N = M ((M )
mN).
Lemma 13. 1. [Id
0]
β= {M ∈ M
⊘/ M is closed and M ⊲
∗βλy
⊘.y
⊘}.
2. [Id
1]
β= [Id
′1]
β= {M ∈ M
(1)/ M is closed and M ⊲
∗βλy
(1).y
(1)}. (Note that Id
′16∈ U .)
3. [D]
β= {M ∈ M
⊘/ M is closed and M ⊲
∗βλy
⊘.y
⊘y
⊘}.
4. [N at
0]
β= {M ∈ M
⊘/ M is closed and M ⊲
∗βλf
⊘.f
⊘or M ⊲
∗βλf
⊘.λy
⊘.(f
⊘)
ny
⊘where n ≥ 1}.
5. [N at
1]
β= {M ∈ M
(1)/ M is closed and M ⊲
∗βλf
(1).f
(1)or M ⊲
∗βλf
(1).λx
(1).(f
(1))
ny
(1)where n ≥ 1}. (Note that N at
′16∈ U .)
6. [N at
′0]
β= {M ∈ M
⊘/ M is closed and M ⊲
∗βλf
⊘.f
⊘or M ⊲
∗βλf
⊘.λy
(1).f
⊘y
(1)}.
7 The completeness theorem
In this section we set out the machinery and prove that completeness holds for
⊢.
We need the following partition of the set of variables {y
L/y ∈ V
2}.
Definition 13. 1. Let L ∈ L
N. We define U
L= {U ∈ U /d(U ) = L} and V
L= {x
L/x ∈ V
2}.
2. Let U ∈ U . We inductively define a set of variables V
Uas follows:
– If d(U ) = ⊘ then:
• V
Uis an infinite set of variables of degree ⊘.
• If U 6= V and d(U) = d(V ) = ⊘, then V
U∩ V
V= ∅.
• S
U∈U⊘
V
U= V
⊘.
– If d(U ) = L, then we put V
U= {y
L/ y
⊘∈ V
U−L}.
Lemma 14. 1. If d(U ), d(V ) L and U
−L= V
−L, then U = V . 2. If d(U ) = L, then V
Uis an infinite subset of V
L.
3. If U 6= V and d(U ) = d(V ) = L, then V
U∩ V
V= ∅.
4. S
U∈UL
V
U= V
L.
5. If y
L∈ V
U, then y
i::L∈ V
eiU
. 6. If y
i::L∈ V
U, then y
L∈ V
U−i.
Proof. 1. If L = (n
i)
m, we have U = e
n1. . . e
nmU
′and V = e
n1. . . e
nmV
′. Then U
−L= U
′, V
−L= V
′and U
′= V
′. Thus U = V . 2. 3. and 4. By induction on L and using 1. 5. Because (e
iU )
−i= U. 6. By definition.
Our partition of the set V
2as above will enable us to give in the next definition useful infinite sets which will contain type environments that will play a crucial role in one particular type interpretation.
Definition 14. 1. Let L ∈ L
N. We denote G
L= {(y
L: U ) / U ∈ U
Land y
L∈ V
U} and H
L= S
KL
G
K. Note that G
Land H
Lare not type environments because they are infinite sets.
2. Let L ∈ L
N, M ∈ M and U ∈ U , we write:
– M : h H
L⊢ U i if there is a type environment Γ ⊂ H
Lwhere M : hΓ ⊢ U i – M : h H
L⊢
∗U i if M ⊲
∗βηN and N : h H
L⊢ Ui
Lemma 15. 1. If Γ ⊂ H
Lthen OK(Γ ).
2. If Γ ⊂ H
Lthen e
iΓ ⊂ H
i::L. 3. If Γ ⊂ H
i::Lthen Γ
−i⊂ H
L.
4. If Γ
1⊂ H
L, Γ
2⊂ H
Kand L K then Γ
1⊓ Γ
2⊂ H
L.
Proof. 1. Let x
K: U ∈ Γ then U ∈ U
Kand so d(U ) = K. 2. and 3. are by lemma 14. 4. First note that by 1., Γ
1⊓ Γ
2is well defined. H
K⊆ H
L. Let (x
R: U
1⊓ U
2) ∈ Γ
1⊓ Γ
2where (x
R: U
1) ∈ Γ
1⊂ H
Land (x
R: U
2) ∈ Γ
2⊂ H
K⊆ H
L, then d(U
1) = d(U
2) = R and x
R∈ V
U1
∩ V
U2
. Hence, by lemma 14, U
1= U
2and Γ
1⊓ Γ
2= Γ
1∪ Γ
2⊂ H
L.
For every L ∈ L
N, we define the set of terms of degree L which contain some free variable x
Kwhere x ∈ V
1and K L.
Definition 15. For every L ∈ L
N, let O
L= {M ∈ M
L/ x
K∈ fv(M ), x ∈ V
1and K L}. It is easy to see that, for every L ∈ L
Nand x ∈ V
1, N
xL⊆ O
L. Lemma 16. 1. (O
L)
+i= O
i::L.
2. If y ∈ V
2and (M y
K) ∈ O
L, then M ∈ O
L3. If M ∈ O
L, M ⋄ N and L K = d(N ), then M N ∈ O
L. 4. If d(M ) = L, L K, M ⋄ N and N ∈ O
K, then M N ∈ O
L.
The crucial interpretation I for the proof of completeness is given as follows:
Definition 16. 1. Let I
βηbe the βη-interpretation defined by: for all type vari- ables a, I
βη(a) = O
⊘∪ {M ∈ M
⊘/ M : h H
⊘⊢
∗ai}.
2. Let I
βbe the β-interpretation defined by: for all type variables a, I
β(a) = O
⊘∪ {M ∈ M
⊘/ M : h H
⊘⊢ ai}.
3. Let I
hbe the h-interpretation defined by: for all type variables a, I
h(a) =
O
⊘∪ {M ∈ M
⊘/ M : h H
⊘⊢ ai}.
The next crucial lemma shows that I is an interpretation and that the inter- pretation of a type of order L contains terms of order L which are typable in these special environments which are parts of the infinite sets of Definition 14.
Lemma 17. Let r ∈ {βη, β, h} and r
′∈ {β, h}
1. If I
r∈ r-int and a ∈ A then I
r(a) is r-saturated and for all x ∈ V
1, N
x⊘⊆ I
r(a).
2. If U ∈ U and d(U ) = L, then I
βη(U ) = O
L∪ {M ∈ M
L/ M : h H
L⊢
∗U i}.
3. If U ∈ U and d(U ) = L, then I
r′(U ) = O
L∪ {M ∈ M
L/ M : h H
L⊢ U i}.
Now, we use this crucial I to establish completeness of our semantics.
Theorem 6 (Completeness of ⊢). Let U ∈ U such that d(U ) = L.
1. [U ]
βη= {M ∈ M
L/ M closed, M ⊲
∗βηN and N : h() ⊢ U i}.
2. [U ]
β= [U ]
h= {M ∈ M
L/ M : h() ⊢ U i}.
3. [U ]
βηis stable by reduction. I.e., If M ∈ [U ]
βηand M ⊲
∗βηN then N ∈ [U ]
βη. Proof. Let r ∈ {β, h, βη}.
1. Let M ∈ [U ]
βη. Then M is a closed term and M ∈ I
βη(U). Hence, by Lemma 17, M ∈ O
L∪ {M ∈ M
L/ M : h H
L⊢
∗U i}. Since M is closed, M 6∈ O
L. Hence, M ∈ {M ∈ M
L/ M : h H
L⊢
∗U i} and so, M ⊲
∗βηN and N : hΓ ⊢ U i where Γ ⊂ H
L. By Theorem 1, N is closed and, by Lemma 4.2, N : h() ⊢ U i.
Conversely, take M closed such that M ⊲
∗βN and N : h() ⊢ U i. Let I ∈ βη-int. By Lemma 11, N ∈ I (U ). By Lemma 10.1, I(U ) is βη-saturated.
Hence, M ∈ I (U ). Thus M ∈ [U ].
2. Let M ∈ [U ]
β. Then M is a closed term and M ∈ I
β(U ). Hence, by Lemma 17, M ∈ O
L∪ {M ∈ M
L/ M : h H
L⊢ U i}. Since M is closed, M 6∈ O
L. Hence, M ∈ {M ∈ M
L/ M : h H
L⊢ U i} and so, M : hΓ ⊢ U i where Γ ⊂ H
L. By Lemma 4.2, M : h() ⊢ U i.
Conversely, take M such that M : h() ⊢ Ui. By Lemma 4.2, M is closed. Let I ∈ β-int. By Lemma 11, M ∈ I (U ). Thus M ∈ [U ]
β.
It is easy to see that [U]
β= [U ]
h.
3. Let M ∈ [U ]
βηand M ⊲
∗βηN . By 1, M is closed, M ⊲
∗βηP and P : h() ⊢ U i.
By confluence Theorem 2, there is Q such that P ⊲
∗βηQ and N ⊲
∗βηQ. By subject reduction Theorem 4, Q : h() ⊢ U i. By Theorem 1, N is closed and,
by 1, N ∈ [U ]
βη.
8 Conclusion
Expansion may be viewed to work like a multi-layered simultaneous substitu-
tion. Moreover, expansion is a crucial part of a procedure for calculating principal
typings and helps support compositional type inference. Because the early def-
initions of expansion were complicated, expansion variables (E-variables) were
introduced to simplify and mechanise expansion. The aim of this paper is to give
a complete semantics for intersection type systems with expansion variables.
The only earlier attempt (see Kamareddine, Nour, Rahli and Wells [13]) at giving a semantics for expansion variables could only handle the λI-calculus, did not allow a universal type, and was incomplete in the presence of more than one expansion variable. This paper overcomes these difficulties and gives a complete semantics for an intersection type system with an arbitrary (possibly infinite) number of expansion variables using a calculus indexed with finite sequences of natural numbers.
References
1. H. P. Barendregt. The Lambda Calculus: Its Syntax and Semantics. North-Holland, revised edition, 1984.
2. S. Carlier, J. Polakow, J. B. Wells, A. J. Kfoury. System E: Expansion variables for flexible typing with linear and non-linear types and intersection types. In Programming Languages & Systems, 13th European Symp. Programming, vol. 2986 of LNCS. Springer-Verlag, 2004.
3. S. Carlier, J. B. Wells. Expansion: the crucial mechanism for type inference with intersection types: A survey and explanation. In Proc. 3rd Int’l Workshop Inter- section Types & Related Systems (ITRS 2004), 2005. The ITRS ’04 proceedings appears as vol. 136 (2005-07-19) of Elec. Notes in Theoret. Comp. Sci.
4. M. Coppo, M. Dezani-Ciancaglini, B. Venneri. Principal type schemes and
λ-calculus semantics. In J. R. Hindley, J. P. Seldin, eds., To H. B. Curry: Essays on Combinatory Logic, Lambda Calculus, and Formalism. Academic Press, 1980.
5. T. Coquand. Completeness theorems and lambda-calculus. In P. Urzyczyn, ed., TLCA, vol. 3461 of Lecture Notes in Computer Science. Springer, 2005.
6. G. Goos, J. Hartmanis, eds.
λ-Calculus and Computer Science Theory, Proceedingsof the Symposium Held in Rome, March 15-27, 1975, vol. 37 of Lecture Notes in Computer Science. Springer-Verlag, 1975.
7. J. R. Hindley. The simple semantics for Coppo-Dezani-Sall´e types. In M. Dezani- Ciancaglini, U. Montanari, eds., International Symposium on Programming, 5th Colloquium, vol. 137 of LNCS, Turin, 1982. Springer-Verlag.
8. J. R. Hindley. The completeness theorem for typing
λ-terms.Theoretical Computer Science, 22, 1983.
9. J. R. Hindley. Curry’s types are complete with respect to F-semantics too. Theo- retical Computer Science, 22, 1983.
10. J. R. Hindley. Basic Simple Type Theory, vol. 42 of Cambridge Tracts in Theoretical Computer Science. Cambridge University Press, 1997.
11. F. Kamareddine, K. Nour. A completeness result for a realisability semantics for an intersection type system. Ann. Pure Appl. Logic, 146(2-3), 2007.
12. F. Kamareddine, K. Nour, V. Rahli, J. B. Wells. A complete realisability semantics for intersection types and infinite expansion variables. Located at
http://www.macs.hw.ac.uk/∼fairouz/papers/drafts/compsem-big.pdf, 2008.
13. F. Kamareddine, K. Nour, V. Rahli, J. B. Wells. Realisability se- mantics for intersection type systems and expansion variables. In ITRS’08. The file is Located at
http://www.macs.hw.ac.uk/∼fairouz/papers/conference-publications/semone.pdf, 2008.