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.

of overloaded declarations satisfies any one of the three rules, it is considered valid overloading. In addition, the overloaded<br />

declarations must have static parameters that are identical (up to α-equivalence). Also, valid overloading for<br />

declarations that contain keyword or varargs parameters is determined by analyzing the expansion of these declarations<br />

into declarations without such parameters, as described in Section 15.4.<br />

Section 33.2 states the Subtype Rule, which stipulates that the parameter type of one declaration be a subtype of the<br />

parameter type of the other. In this case, there is no possibility of ambiguous calls, because one declaration is more<br />

specific than the other. This section also places a restriction on the return types of the overloaded declarations to ensure<br />

that type safety is not violated. Section 33.3 defines the Incompatibility Rule that, if satisfied by a pair of declarations,<br />

guarantees that neither declaration is applicable to the same functional call. In Section 33.4, the More Specific Rule<br />

requires the existence of a declaration that is more specific than both overloaded declarations in the situation that both<br />

are applicable to a given call.<br />

In the remainder of this chapter we build on the terminology and notation defined in Chapter 15 and Chapter 17.<br />

33.2 Subtype Rule<br />

If the parameter type of one declaration is a subtype of the parameter type of another then there is no possibility<br />

of ambiguous calls because the most specific declaration will be dispatched to. This is the basis of the Subtype<br />

Rule. <strong>The</strong> Subtype Rule also requires a relationship between the return types of the two declarations. Without such a<br />

requirement, a program may be statically well typed but have a runtime error because the return type of a dynamically<br />

resolved functional is not a subtype of the return type of the statically resolved functional.<br />

<strong>The</strong> Subtype Rule for Functions and Functional Methods: Suppose that f (P) : U and f (Q) : V are two distinct<br />

function or functional method declarations both visible at some point Z in a <strong>Fortress</strong> program (Z need not be the site<br />

of a call). If P ≺ Q and U ≼ V then f (P) and f (Q) are valid overloadings.<br />

<strong>The</strong> Subtype Rule for Dotted Methods: Suppose that P 0 .f (P) : U and Q 0 .f (Q) : V are two distinct dotted<br />

method declarations provided by a trait or object C. If (P 0 ,P) ≺ (Q 0 ,Q) and U ≼ V then P 0 .f (P) and Q 0 .f (Q)<br />

are valid overloadings.<br />

33.3 Incompatibility Rule<br />

<strong>The</strong> basic idea behind the Incompatibility Rule is that if there is no call to which two overloaded declarations are both<br />

applicable then there is no potential for ambiguous calls. In such a case, we say that the declarations are incompatible.<br />

Without coercion, incompatibility is equivalent to exclusion. However, the presence of coercion complicates the<br />

definition of incompatibility. To formally define incompatibility we first define the following notation. For types T<br />

and U, we say that T and U do not share coercions, and write T ≬ U, if any type that coerces to T excludes any type<br />

that coerces to U:<br />

T ≬ U ⇐⇒ ∀A, B : A→T ∧ B →U =⇒ A ♦ B.<br />

We say that T is incompatible with U, and write T U, if T and U exclude, reject each other, and do not share<br />

228

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

Saved successfully!

Ooh no, something went wrong!