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.

<strong>Fortress</strong> also allows coercion between types (see Chapter 17). A coercion from T to U is defined in the declaration of<br />

U. We write T →U if U defines a coercion from T . We say that T can be coerced to U, and write T U, if U defines<br />

a coercion from T or any supertype of T : T U ⇐⇒ ∃T ′ : T ≼ T ′ ∧ T ′ →U.<br />

<strong>The</strong> <strong>Fortress</strong> type hierarchy is acyclic with respect to both subtyping and coercion relations except for the following:<br />

• <strong>The</strong> trait Object is a single root of the type hierarchy and it forms a cycle as described in Chapter 23.<br />

• <strong>The</strong>re exists a bidirectional coercion between two tuple types if and only if they have the same sorted form.<br />

8.2 Trait Types<br />

Syntax:<br />

TypeRef ::= TraitType<br />

Traits are declared by trait declarations (described in Chapter 9). A trait has a trait type of the same name. A significant<br />

portion of <strong>Fortress</strong> types are trait types.<br />

8.3 Object Trait Types<br />

Named objects are declared by object declarations (described in Chapter 10) and anonymous objects are described<br />

by object expressions (described in Section 13.9). A named object has an object trait type of the same name and an<br />

anonymous object has an anonymous object trait type. An object trait type is a special kind of trait type. An object<br />

trait type extends all of the declared supertraits of the object. No other objects can have the object trait type and no<br />

trait type can extend an object trait type (i.e., an object trait type implicitly has an empty comprises clause).<br />

8.4 Tuple Types<br />

Syntax:<br />

TypeRef ::= TupleType<br />

TupleType ::= (TypeRef (,TypeRef ) + )<br />

| ([TypeRef ( , TypeRef ) ∗ , ] TypeRef ... )<br />

| ([TypeRef ( , TypeRef ) ∗ , ] [TypeRef ... , ] Id = TypeRef ( , Id = TypeRef ) ∗ )<br />

A tuple is an ordered sequence of keyword-value pairs. See Section 13.28 for a discussion of tuple expressions. A<br />

tuple type consists of a parenthesized, comma-separated list of element types where each element type is one of the<br />

following kinds:<br />

• A plain type “T ”<br />

• A varargs type “T . . . ”<br />

• A keyword-type pair “identifier = T ”<br />

<strong>The</strong> following restrictions apply: No two keyword-type pairs may have the same keyword. No keyword-type pair may<br />

precede a plain type. No varargs type may follow a keyword-type pair or precede a plain type. <strong>The</strong>re must be at least<br />

one element type. If there is exactly one element type, it must be a varargs type or a keyword-type pair (because “(T) ”<br />

is simply a type in parentheses, not a tuple type). Also, there can be at most one element type with varargs type.<br />

An element type in tuple type X corresponds to one in tuple type Y if and only if:<br />

65

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

Saved successfully!

Ooh no, something went wrong!