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.

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

– there is a declaration f (P ′ ∩ Q ′ ) visible at Z.<br />

Recall that P ∩ Q is the intersection of types P and Q as defined in Section 8.8. If for some type S we have S ≼ P<br />

and S ≼ Q then S ≼ (P ∩ Q), but it’s not necessarily the case that S = (P ∩ Q) since another type may be more<br />

specific than both P and Q. For example, suppose the following:<br />

trait S comprises {U, V } end<br />

trait T comprises {V, W } end<br />

trait U extends S excludes W end<br />

trait V extends {S, T } end<br />

trait W extends T end<br />

f(s :S) = 1<br />

f(t :T) = 1<br />

f(v : V ) = 1<br />

Because of the comprises clauses of S and T and the excludes clause of U, any subtype of both S and T must be<br />

a subtype of V . Thus, V = S ∩ T , and the declaration f(V ) “disambiguates” f(S) and f(T), i.e., it is applicable to<br />

and more specific for any call to which both f(S) and f(T) are applicable.<br />

This requirement should not be difficult to obey, especially because the compiler can give useful feedback. First<br />

example:<br />

foo(x :Number, y : Z64) = . . .<br />

foo(x : Z64, y : Number) = . . .<br />

Assuming that Z64 ≺ Number, the compiler reports that these two declarations are a problem because of ambiguity<br />

and suggests that a new declaration for foo(Z64, Z64) would resolve the ambiguity. Second example:<br />

bar(x :Printable) = . . .<br />

bar(x :Throwable) = . . .<br />

Assuming that Printable and Throwable are neither comparable by the subtyping relation nor disjoint, the compiler<br />

reports that these two declarations are a problem because Printable and Throwable are incomparable but possibly<br />

overlapping types. As a result, these two declarations are statically rejected.<br />

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

provided by a trait or object C such that neither (P 0 ,P) nor (Q 0 ,Q) is a subtype of the other and P and Q are<br />

not incompatible with one another. Let S be the set of types that P defines coercions from and T be the set of types<br />

that Q defines coercions from. P 0 .f (P) and Q 0 .f (Q) are valid overloadings if all of the following hold:<br />

• either P ♦ Q or there is a declaration R 0 .f (P ∩ Q) provided by C with R 0 ≼ (P 0 ∩ Q 0 ), 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 R 0 .f (P ′ ∩ Q ′ ) provided by C with R 0 ≼ (P 0 ∩ Q 0 ).<br />

Unlike for functions and functional methods, the More Specific Rule for dotted methods only applies to dotted methods<br />

that are provided by the same trait or object. This is possible because two dotted methods are applicable to a given<br />

call A 0 .f(A) only if they are both provided by the trait or object A 0 . This is not the case for functional methods as the<br />

following rule shows.<br />

230

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

Saved successfully!

Ooh no, something went wrong!