L - Università di Torino

advertisement
Characterizing convergent terms
in object calculi via intersection
types
Ugo de’Liguoro
Università di Torino
TLCA’01
Toward logic semantics of objects
• logic semantics amounts to type characterization of
relevant computational properties;
• it is a tool for the study of syntactical properties
(normalization, strong normalization, standardization);
• it can be used to achieve a concrete description of
denotational models (filter models, domain logic);
• it could be a tool to analyze notions of subtyping (like
matching) which otherwise have only a syntactical
definition (this for the future).
The type-free ς-calculus [AC96]
a, b ::= x | [li = ς(xi)bi i∈I] | a.l | a.l ⇐ ς(x)b
Define the one-step reduction relation by
i)
[li = ς(xi)bi i∈I].lj →ς bj{[li = ς(xi)bi i∈I] /xj}
ii)
[li = ς(xi)a i∈I].lj ⇐ ς(x)b →ς [li = ς(xi)a i∈I\{j},lj = ς(x)b]
iii)
a →ς a' ⇒ a.l →ς a'.l
iv)
a →ς a' ⇒ a .l ⇐ ς(x)b →ς a'.l ⇐ ς(x)b
Defining values as v ::= [li = ς(xi)bi i∈I] we have
*
a↓v ⇔ a →
ςv
Remark: →ς is weaker than one-step reduction in [AC96]
Existing type systems in object
calculi do not catch termination
In Abadi and Cardelli “Theory of Objects”, for any type
A, the diverging term:
[l = ς(x:[l:A])x.l].l
has type A (so any type has a fully undefined inhabitant).
In terms of type assignment systems this can be restated
as:
[l = ς(x)x.l].l has any type.
Remark: this is not a criticism, as the same holds for PCF
(e.g. fix x.x) or Pascal.
The present approach
• We consider a type-free λ-calculus and an intepretation
of (type-free) ς-calculus respecting and preserving
convergency;
• we then provide a characterization of convergent λterms via an intersection type assignment system.
translation
ς-calculus
semantics
λ-calculus
[]
ΛR: a λ-calculus with records
record
M, N ::= x | λx.M | MN | ⟨li = Mi i∈I⟩ | M·l | M·l := N
(β) (λx.M)N → M[N/x]
(ν)
M → M' ⇒ MN → M'N
selection
(R1) ⟨li = Mi i∈I⟩ ·lj → Mj , if j ∈ I
update
(R2) M → M' ⇒ M·l → M'·l
(R3) ⟨li = Mi i∈I⟩ ·lj := N → ⟨li = Mi i∈I\{j}, lj = N⟩, if j ∈ I
(R4) M → M' ⇒ M·l := N → M'·l := N
The self-application interpretation
Define (after Kamin 1988 and Abadi Cardelli 1996) a map:
[ ]S : ς-terms → ΛR
[x]S
=
x
[[li = ς(xi)bi i∈I] ]S
=
⟨li = λxi .[bi]S i∈I⟩
[a.l ]S
=
([a]S ·l ) [a]S
[a.l ⇐ ς(x)b]S
=
[a]S ·l := λx.[b]S
Convergency
Let V ::= λx.M | ⟨li = Mi i∈I⟩ be the definition of values in the λcalculus with records; then the convergency predicate is defined
by:
* V
M⇓ ⇔ ∃ V. M →
An irreducible term like (λx.x) ·l is a normal form but not a
value (hence it “diverges”).
Theorem. For any ς-term a it is the case that
a ↓ ⇔ [a]S ⇓.
Goal: give a characterization of the convergency predicate via
some type assignment system.
Known results about λ-calculus
Some relevant computational properties of type free λ-terms
are characterized via intersection type assignment systems.
E.g. in BCD system (with type inequalities and a
subsumption rule):
• M is solvable (has hnf) iff Γ |— M : σ ≠ ω
• M is normalizable (has nf) iff Γ |— M : σ and ω ∉Γ, σ
• M is strongly normalizable iff D: Γ |— M : σ, ω ∉Γ, σ, D
Similar results hold in system CDVω (called DΩ by
Krivine), where no type inequalities are considered.
Intersection types for ΛR
σ, τ ::= α | ω | σ → τ | σ ∧ τ | ⟨li: σi
i∈I⟩
To the standard intersection type rules we add rules for records:
(Rec)
(Sel)
Γ |— Mi: σi ∀i ∈ I ⊇ J
Γ |— ⟨li = Mi i ∈ I⟩ : ⟨li: σi
Γ |— M : ⟨li: σi
i∈J⟩
i∈I⟩
Γ |— M ·lj : σj
(Upd)
Γ |— M : ⟨li: σi i∈I⟩ j ∈ I Γ |—N : τ
Γ |— M ·lj := N : ⟨li: σi i∈I\{j}, lj : τ ⟩
j∈I
Comments on (Upd) rule
Consider the following variant of (Upd), closer to the typing of
overriding in the Object Calculus:
same type
(Upd’)
Γ |— M : ⟨li: σi i∈I⟩ j ∈ I Γ |— N : σj
Γ |— M ·lj := N : ⟨li: σi i∈I⟩
In this way we lose type invariance under expansion:
⟨l = Ω⟩ ·l := (λx.x) → ⟨l = λx.x⟩
Now
⟨l = λx.x⟩ : ⟨l : σ → σ⟩
but, using (Upd’) in place of (Upd), we have at best
⟨l = Ω⟩ ·l := (λx.x) : ⟨l : ω⟩
Invariance under reduction
The main reason for using intersection types and ω,
(∧ I)
Γ |— M : σ
Γ |— M : τ
Γ |— M : σ ∧ τ
(ω)
Γ |— M : ω
is type invariance under subject reduction and expansion:
Subject reduction and expansion theorem. In the type
system with ω, intersection, arrow and record types:
• if Γ |— M : σ and M → N then Γ |— N : σ
• if Γ |— N : σ and M → N then Γ |— M : σ
Some typing examples
a = [l = ς(x)3, m = ς(x)x.l⇐ ς(y)x.l+1] : [l:int, m:[]]
translates to
M = ⟨l = λx.3, m = λx.x ·l:= λy.(x ·l)x+1⟩
which is typable by
⟨l : ω → int, m : ω⟩
which is close to the Ob1<: type, but also by
⟨l : α → int, m : σ∧α → σ⟩
where σ = ⟨l : α → int, m : β⟩ (α, β type variables), which does
not contain ω, as expected being M a normal form.
Type interpretation
Types are interpreted as sets of closed terms. Let us define
F = {λx.M | λx.M ∈ ΛR0} and
R = {⟨li = Mi i∈I⟩ | ⟨li = Mi i∈I⟩ ∈ ΛR0}.
Then, given some interpretation ℑ of type variables,
[α]ℑ = ℑ(α)
[ω]ℑ = ΛR0
[σ ∧ τ]ℑ = [σ]ℑ ∩ [τ]ℑ
[σ → τ]ℑ = {M ∈ ΛR0 | ∃ F ∈ F. M⇓F and ∀N ∈ [σ]ℑ . FN ∈ [τ]ℑ }
[⟨li: σi
i∈I⟩]
ℑ
= {M ∈ ΛR0| ∃ R ∈ R. M⇓R and ∀i ∈ I . R ·li ∈ [σi ]ℑ }
Type inclusion
Define:
σ ≤ τ ⇔ ∀ ℑ. [σ]ℑ ⊆ [τ]ℑ
and σ = τ if σ ≤ τ and σ ≥ τ; then:
• I ⊇ J ⇒ ⟨li : σi
i∈I⟩
≤ ⟨lj : σi
• ∀ i ∈ I . σi ≤ τi ⇒ ⟨li : σi
• ⟨li : σi
i∈I⟩
i∈I⟩
j∈J⟩
≤ ⟨li : τi
(sub width)
i∈I⟩
(sub depth)
= Λi∈I ⟨li : σi⟩
• ⟨l : σ⟩ ∧ ⟨l : τ⟩ = ⟨l : σ ∧ τ⟩
Remark. There are empty types, e.g. (ω → ω) ∧ ⟨l : ω⟩.
The characterization theorem
If ℑ(α) is closed under (closed) expansions for all α, then
[σ]ℑ is such for any σ: we say that ℑ is saturated.
Soundeness lemma. If ℑ is saturated, ϑ: Var → ΛR0 a
closed substitution s.t. ϑ(x) ∈ [σ]ℑ for all x:σ ∈ Γ, then
Γ |— M : τ ⇒ Mϑ ∈ [τ]ℑ
Characterization theorem. For any M ∈ ΛR :
• M⇓F , for some F ∈ F, iff Γ |— M : ω → ω, for some Γ;
• M⇓R , for some R ∈ R, iff Γ |— M : ⟨⟩, for some Γ.
In particular, for any closed ς-term a:
a ↓ iff |— [a]S : ⟨⟩.
Conclusions and further work
The present work suggests that, beside PER models and standard
domain theoretic techniques like solving domain equations, there
is a further way to build and study models of object calculi,
namely via type assignment and domain logic: filter models.
This remained implicit since a key problem, which is under
study, is a reasonable interpretion of typed terms and equalities,
and a comparison between the (typed) theories one obtains and
theories of known models as well as operational theories, like the
bisimulation theory of objects by Gordon and Rees.
Further applications are expected, essentially extending program
logic as it has been developed in the functional case, to object
calculi.
Next steps
• Ignoring empty types and considering type inclusion, a filter
model comes out, which is a solution of the domain equation
D = A + (L → D) + (D → D).
• Types from typed object calculi may be interpreted as PER
over D: is there a “logical” characterization of them?
• Given type interpretation, also typed equations are interpreted,
and models can be compared w.r.t. their theories. Interesting
would be the study of the bisimulation theory by Gordon and
Rees.
Download