19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Proof. For the purpose of contradiction suppose there are two declarations f (P) and f (Q) in σ ′ . Since both f (P) and<br />

f (Q) are applicable with coercion to f (A) and |Σ| = 0 there must exist a coercion from some type P ′ to P and a<br />

coercion from some type Q ′ to Q such that A ≼ P ′ ∩ Q ′ . <strong>The</strong>refore it is not the case that P Q. By the overloading<br />

restrictions, P ≠ Q and either P ⊳ Q or Q ⊳ P or for all P ′ ∈ S and Q ′ ∈ T either P ′ ♦ Q ′ , or there is a declaration<br />

f (P ′ ∩Q ′ ) visible at Z. If P ⊳ Q or Q ⊳ P then we contradict our assumption. Otherwise, if there exists a declaration<br />

f (P ′ ∩ Q ′ ) visible at Z then this declaration is applicable to f (A) without coercion. This contradicts |Σ| = 0. If such<br />

a declaration does not exist then it must be the case that P ′ ♦ Q ′ . <strong>The</strong>n both f (P) and f (Q) can not be applicable to<br />

the call f (A) which is a contradiction.<br />

<strong>The</strong>orem 1. If |Σ| = 0 and |Σ ′ | ≠ 0 then |σ ′ | = 1.<br />

Proof. Follows from Lemmas 2 and 3.<br />

B.2 Proof of Overloading Resolution for Functions<br />

This section proves that the restrictions placed on overloaded function declarations are sufficient to guarantee no<br />

undefined nor ambiguous call at run time (the case for methods is analogous).<br />

Consider a static function call f (A) at some program point Z and its corresponding dynamic function call f (X). Let<br />

∆ be the set of parameter types of function declarations of f that are visible at Z and applicable to the dynamic call<br />

f (X). Let Σ be the set of parameter types of function declarations of f that are visible at Z and applicable to the static<br />

call f (A). Moreover, let σ be the subset of Σ for which no type in Σ is more specific and let δ be the subset of ∆ for<br />

which no type in ∆ is more specific:<br />

σ = {S ∈ Σ | ¬∃S ′ ∈ Σ : S ′ ≺ S }<br />

δ = {D ∈ ∆ | ¬∃D ′ ∈ ∆ : D ′ ≺ D }.<br />

Below we prove:<br />

|Σ| ≠ 0 implies |σ| = 1, and<br />

|Σ| ≠ 0 implies |δ| = 1.<br />

Informally, if any declaration is applicable to a static call then there exists a single most specific declaration that is<br />

applicable to the static call and a single most specific declaration that is applicable to the corresponding dynamic call.<br />

Lemma 4. Σ ⊆ ∆.<br />

Proof. Notice that X ≼ A by type soundness. If f (P) is applicable to the call f (A) then A ≼ P. Notice that X ≼ A<br />

implies X ≼ P. <strong>The</strong>refore f (P) is applicable to the call f (X).<br />

Lemma 5. If |∆| ≥ 1 then |δ| ≥ 1. Also, if |Σ| ≥ 1 then |σ| ≥ 1.<br />

Proof. Follows from Lemma 1 where S is the set of all types, A is ∆ and Σ respectively, and the relation ≺ is acyclic<br />

and irreflexive.<br />

Lemma 6. If |Σ| ≥ 1 then |δ| ≥ 1.<br />

Proof. Follows from Lemmas 4 and 5.<br />

Lemma 7. |σ| ≤ 1. Also, |δ| ≤ 1.<br />

338

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!