19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Appendix B<br />

Overloaded Functional Declarations<br />

As mentioned in Chapter 33, this appendix proves that the restrictions discussed in Chapter 33 guarantee no undefined<br />

nor ambiguous call at run time.<br />

B.1 Proof of Coercion Resolution for Functions<br />

This section proves that the restrictions discussed in the previous sections guarantee the static resolution of coercion<br />

(described in Section 17.5) is well defined for functions (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 static call f (A).<br />

Let Σ ′ be the set of parameter types of function declarations of f that are visible at Z and applicable with coercion to<br />

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

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

We prove the following:<br />

|Σ| = 0 and |Σ ′ | ≠ 0 imply |σ ′ | = 1.<br />

Informally, if no declaration is applicable to a static call but there is a declaration that is applicable with coercion then<br />

there exists a single most specific declaration that is applicable with coercion to the static call.<br />

Lemma 1. Given an acyclic, irreflexive binary relation R on a set S, and a finite nonempty subset A of S, the set<br />

{a ∈ A|¬∃a ′ ∈ A : (a ′ , a) ∈ R} is nonempty.<br />

Proof. Consider the relation R on S as a directed acyclic graph. Let A represent a subgraph. <strong>The</strong>n the Lemma amounts<br />

to proving that there exists a node in the graph represented by A with no edges pointing to it. This follows from the<br />

fact that A is finite and the graph is acyclic.<br />

Lemma 2. If |Σ ′ | ≥ 1 then |σ ′ | ≥ 1.<br />

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

Lemma 3. If |Σ| = 0 then |σ ′ | ≤ 1.<br />

337

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

Saved successfully!

Ooh no, something went wrong!