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.

• both are plain types in the same position,<br />

• both are varargs types, or<br />

• both are keyword-type pairs with the same keyword.<br />

Every tuple type is a subtype of Object, and no other nontuple type. <strong>The</strong>re is no other type that encompasses all<br />

tuples. Tuple types are covariant; a tuple type X is a subtype of tuple type Y if and only if:<br />

• the correspondence between their element types is bijective;<br />

• for each element type in X , the type in the element type is a subtype of the type in the corresponding element<br />

type in Y ; and<br />

• the keyword-type pairs in X and Y appear in the same order.<br />

Note that, unlike record types in some other programming languages, the tuple type (foo = P,bar = Q,baz = R)<br />

is not a subtype of (foo = P,bar = Q) , nor is (P, Q, R) a subtype of (P, Q) . While (Z, Z) is not a subtype of<br />

(Z . . .) , there exists a coercion from the former to the latter (as described in Section 17.7).<br />

For every tuple type X there is a tuple type X ′ that is the “sorted form” of the type, created by simply reordering the<br />

keyword-type pairs so that their keywords are in lexicographically ascending order. X ′ may be the same as X (as,<br />

for example, if X contains fewer than two keyword-type pairs). <strong>The</strong>re is a coercion from tuple type X to tuple type<br />

Y if and only if X and Y have the same sorted form.<br />

A tuple type excludes any nontuple type other than Object. Two tuple types exclude each other unless the correspondence<br />

between their element types is bijective. Two tuple types with a bijective correspondence between their element<br />

types exclude each other if either any type in an element type in one excludes the type in the corresponding element<br />

type in the other, or their keyword-type pairs do not appear in the same order.<br />

Intersection of nonexclusive tuple types are defined elementwise; the intersection of nonexclusive tuple type X and<br />

Y is a tuple type with exactly corresponding elements, where the type in each element type is the intersection of the<br />

types in the corresponding element types of X and Y . Note that intersection of any exclusive types is BottomType<br />

as described in Section 8.6.<br />

8.5 Arrow Types<br />

Syntax:<br />

TypeRef ::= ArrowType<br />

ArrowType ::= ArrowTypeRef → ArrowTypeRef [Throws]<br />

ArrowTypeRef ::= TypeRef (× TypeRef ) ∗<br />

| TypeRef ˆ Number<br />

Functions can be passed as arguments and returned as values. See Chapter 12 for a discussion of functions. <strong>The</strong> types<br />

of function values are called arrow types. Every arrow type is a subtype of Object. Arrow types are not trait types.<br />

<strong>The</strong>y cannot be extended by other trait types. Syntactically, an arrow type consists of the type of a parameter to the<br />

function followed by the token → , followed by the type of a return value, and optionally a throws clause which<br />

specifies thrown checked exceptions. Here are some examples:<br />

(R64, R64) → R64<br />

N → (N, N) throws IOException<br />

(String, N . . .,p = Printer) → N<br />

<strong>Fortress</strong> supports alternative mathematical notations for arrow types whose parameter types or return types are tuple<br />

types:<br />

66

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

Saved successfully!

Ooh no, something went wrong!