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.

the dynamic type of the value the expression evaluates to (unlike a type ascription described in Section 13.30). It is<br />

usually for accessing methods provided by supertraits. When multiple supertraits provide different methods with the<br />

same name, a subtrait may access a particular method from one of the supertraits using a type assumption. <strong>The</strong> static<br />

type of the supertrait indicates whether a definition of the method is provided by the supertrait. If the concrete method<br />

is not provided exist, it is a static error. <strong>The</strong> keyword super in the Java Programming <strong>Language</strong> is an example of a<br />

type assumption.<br />

13.32 Expression-like Functions<br />

For convenience, the <strong>Fortress</strong> standard libraries provide functions such as cast and instanceOf that are often provided<br />

by other programming languages.<br />

13.32.1 Casting<br />

Although there is no “casting” operator (equivalent to casts in the Java Programming <strong>Language</strong>) built into <strong>Fortress</strong>,<br />

the effect of a cast can be provided by the following function:<br />

castT(x) :T =<br />

typecase x in<br />

T ⇒ x<br />

else ⇒throw CastException<br />

end<br />

<strong>The</strong> function converts the type of its argument to a given type. If the static type of the argument is not a subtype of<br />

the given type, a CastException is thrown. For convenience, the function cast is included in the <strong>Fortress</strong> standard<br />

libraries.<br />

13.32.2 Instanceof Testing<br />

Although there is no “instanceof” operator (equivalent to instanceof testing in the Java Programming <strong>Language</strong>) built<br />

into <strong>Fortress</strong>, the effect of an instanceof testing can be provided by the following function:<br />

instanceOf T(x) :Boolean =<br />

typecase x in<br />

T ⇒ true<br />

else ⇒ false<br />

end<br />

<strong>The</strong> function tests whether its argument has a given type and returns a boolean value. For convenience, the function<br />

instanceOf is included in the <strong>Fortress</strong> standard libraries.<br />

13.32.3 Ignoring Values<br />

For convenience, the function ignore (equivalent to the ignore function in the Objective Caml programming language)<br />

is included in the <strong>Fortress</strong> standard libraries:<br />

ignore(x) = ()<br />

<strong>The</strong> function discards the value of its argument and returns () . For example, the following:<br />

116

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

Saved successfully!

Ooh no, something went wrong!