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>The</strong> <strong>Fortress</strong> standard libraries also define other simple standard types such as Object, Exception, Boolean, and<br />

BooleanInterval as well as low-level binary data types such as LinearSequence, HeapSequence, and BinaryWord.<br />

See Parts III and V for discussions of the <strong>Fortress</strong> standard libraries.<br />

8.8 Intersection and Union Types<br />

For every finite set of types, there is a type denoting a unique intersection of those types. <strong>The</strong> intersection of a set of<br />

types S is a subtype of every type T ∈ S and of the intersection of every subset of S. <strong>The</strong>re is also a type denoting a<br />

unique union of those types. <strong>The</strong> union of a set of types S is a supertype of every type T ∈ S and of the union of every<br />

subset of S. Neither intersection types nor union types are first-class types; they are used solely for type inference (as<br />

described in Chapter 20) and they cannot be expressed directly in programs.<br />

<strong>The</strong> intersection of a set of types S is equal to a named type U when any subtype of every type T ∈ S and of the<br />

intersection of every subset of S is a subtype of U. Similarly, the union of a set of types S is equal to a named type U<br />

when any supertype of every type T ∈ S and of the union of every subset of S is a supertype of U. For example:<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 />

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 .<br />

Intersection types (denoted by ∩) possess the following properties:<br />

• Commutativity: T ∩ U = U ∩ T .<br />

• Associativity: S ∩ (T ∩ U) = (S ∩ T) ∩ U.<br />

• Subsumption: If S ≼ T then S ∩ T = S.<br />

• Preservation of shared subtypes: If T ≼ S and T ≼ U then T ≼ S ∩ U.<br />

• Preservation of supertype: If S ≼ T then ∀U. S ∩ U ≼ T .<br />

• Distribution over union types: S ∩ (T ∪ U) = (S ∩ T) ∪ (S ∩ U).<br />

Union types (denoted by ∪) possess the following properties:<br />

• Commutativity: T ∪ U = U ∪ T .<br />

• Associativity: S ∪ (T ∪ U) = (S ∪ T) ∪ U.<br />

• Subsumption: If S ≼ T then S ∪ T = T .<br />

• Preservation of shared supertypes: If S ≼ T and U ≼ T then S ∪ U ≼ T .<br />

• Preservation of subtype: If T ≼ S then ∀U. T ≼ S ∪ U.<br />

• Distribution over intersection types: S ∪ (T ∩ U) = (S ∪ T) ∩ (S ∪ U).<br />

8.9 Type Aliases<br />

Syntax:<br />

68

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

Saved successfully!

Ooh no, something went wrong!