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.

<strong>The</strong> More Specific Rule for Functional Methods: Suppose that f (P) and f (Q) are two functional method declarations<br />

occurring in trait or object declarations such that neither P nor Q is a subtype of the other and P and Q are<br />

not incompatible with one another. Let f (P) and f (Q) have self parameters at i and j respectively. Also, let S be the<br />

set of types that P defines coercions from and T be the set of types that Q defines coercions from. f (P) and f (Q) are<br />

valid overloadings if all of the following hold:<br />

• i = j<br />

• either P ♦ Q or if there exists a trait or object C that provides both f (P) and f (Q) then P ≠ Q and there is a<br />

declaration f (P ∩ Q) provide by C, and<br />

• either P ⊳ Q or Q ⊳ P or for all P ′ ∈ S and Q ′ ∈ T one of the two conditions holds:<br />

– P ′ ♦ Q ′ , or<br />

– there is a declaration f (P ′ ∩ Q ′ ) provided by C.<br />

Verifying the More Specific Rule for functional methods can be thought of as a two step process. First there must be no<br />

ambiguity caused by the position of the self parameter. To guarantee this, overloaded declarations with different self<br />

parameter positions must be incompatible with one another. Second, functional method declarations that create the<br />

potential for ambiguity because neither is more specific than the other must be accompanied by a third disambiguating<br />

declaration that is more specific than both. Notice that the second step is similar to the overloading requirements<br />

placed on dotted methods.<br />

33.5 Coercion and Overloading Resolution<br />

<strong>The</strong> restrictions on overloaded declarations given in this chapter are sufficient to prove the following two facts:<br />

1. If no declaration is applicable to a static call but there is a declaration that is applicable with coercion then there<br />

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

2. If any declaration is applicable to a static call then there exists a single most specific declaration that is applicable<br />

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

Moreover, we can prove that the most specific declaration that is applicable to a dynamic call is more specific than the<br />

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

Appendix B formally proves that the restrictions discussed in the previous sections guarantee the static resolution<br />

of coercion (described in Section 17.5) is well defined for functions (the case for methods is analogous). Also in<br />

Appendix B is a proof that the restrictions placed on overloaded function declarations are sufficient to guarantee no<br />

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

231

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

Saved successfully!

Ooh no, something went wrong!