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.

trait B extends A end<br />

trait C extends B<br />

coercion (a :A) = . . .<br />

end<br />

17.7 Coercions for Tuple and Arrow Types<br />

Unlike other types, tuple types (described in Section 8.4) and arrow types (described in Section 8.5) are not defined<br />

explicitly. <strong>The</strong>refore coercions to these types are also not defined explicitly. Instead, the following rules describe when<br />

these coercions are implicitly defined.<br />

<strong>The</strong>re is a coercion from a tuple type X to a tuple type Y if all the following conditions hold:<br />

1. X is not a subtype of Y ;<br />

2. for every plain type T in Y , there is a corresponding plain type in X whose type is substitutable for T ;<br />

3. if neither X nor Y has a varargs type, then they have the same number of plain types;<br />

4. if X has a varargs type, then Y has a varargs type, the type S of the varargs type S... in X is substitutable for<br />

the type T of the varargs type T... in Y , and X and Y have the same number of plain types;<br />

5. if X has no varargs type and Y has a varargs type T..., then every plain type in X that has no corresponding<br />

plain type in Y is substitutable for T ; and<br />

6. the correspondence between keyword-type pairs in X and Y is bijective, and the type of each such pair in X is<br />

substitutable for the type in the corresponding pair in Y .<br />

Tuple type coercions are invoked by distributing the coercion elementwise. However, if an element type of the tuple<br />

type being coerced from is a subtype of the corresponding element type of the tuple type being coerced to, the coercion<br />

is ignored. For example, the following coercions:<br />

(A, B). coercion (x, y)<br />

(kwd = A). coercion (kwd = x)<br />

are rewritten to:<br />

(A. coercion (x), B. coercion (y))<br />

(kwd = A. coercion (x))<br />

However, if the type of y were a subtype of B then the first coercion would instead be rewritten to:<br />

(A. coercion (x), y)<br />

Coercions to varargs types such as the following:<br />

(A . . .). coercion (x, y)<br />

are invoked by applying the coercion to the type in the varargs type, A in this example, to each of the elements of the<br />

tuple. Additionally, there is a coercion from any type T to a tuple type solely with varargs type (T . . .) .<br />

<strong>The</strong>re is a coercion from arrow type “ A → B throws C ” to arrow type “D → E throws F ” if all of the following<br />

conditions hold:<br />

1. “ A → B throws C ” is not a subtype of “ D → E throws F ”;<br />

2. D is substitutable for A;<br />

143

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

Saved successfully!

Ooh no, something went wrong!