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.

An infix/multifix operator declaration may also be invoked by a prefix or nofix (but not a postfix) operator application<br />

if the declaration is applicable.<br />

Note that superscripting (ˆ) may be defined using an infix operator declaration even though it has very high precedence<br />

and cannot be used as a multifix operator. (An operator declaration for superscripting should have exactly two value<br />

parameters.)<br />

Example:<br />

opr MAXT extends Rational(x :T, y :T) :T = if x > y then x else y end<br />

34.2 Prefix Operator Declarations<br />

A prefix operator declaration has the special reserved word opr and then an operator name where a functional declaration<br />

would have an identifier. <strong>The</strong> declaration must have one value parameter, which must not be a keyword parameter<br />

or varargs parameter. Static parameters may also be present, between the operator and the parameter list.<br />

An expression consisting of a prefix operator applied to an expression will invoke a prefix operator declaration. <strong>The</strong><br />

compiler considers all prefix and infix/multifix operator declarations for that operator that are both accessible and<br />

applicable, and the most specific operator declaration is chosen according to the usual rules for overloaded functionals.<br />

Example:<br />

opr ˜(x :Widget) :Widget = x.invert()<br />

34.3 Postfix Operator Declarations<br />

A postfix operator declaration has the special reserved word opr where a functional declaration would have an identifier;<br />

the operator name itself follows the parameter list. <strong>The</strong> declaration must have one value parameter, which must<br />

not be a keyword parameter or varargs parameter. Static parameters may also be present, between the special reserved<br />

word opr and the parameter list.<br />

An expression consisting of a postfix operator applied to an expression will invoke a postfix operator declaration. <strong>The</strong><br />

compiler considers all postfix operator declarations for that operator that are both accessible and applicable, and the<br />

most specific operator declaration is chosen according to the usual rules for overloaded functionals.<br />

Example:<br />

opr (n :Integer)! = ∏ [i ← 1 : n]i (∗ factorial ∗)<br />

34.4 Nofix Operator Declarations<br />

A nofix operator declaration has the special reserved word opr and then an operator name where a functional declaration<br />

would have an identifier. <strong>The</strong> declaration must have no parameters.<br />

An expression consisting only of a nofix operator will invoke a nofix operator declaration. <strong>The</strong> compiler considers all<br />

nofix and infix/multifix operator declarations for that operator that are both accessible and applicable, and the most<br />

specific operator declaration is chosen according to the usual rules for overloaded functionals.<br />

Uses for nofix operators are rare, but those rare examples are very useful. For example, the colon operator is used to<br />

construct subscripting ranges, and it is the nofix declaration of : that allows a lone : to be used as a subscript:<br />

opr : () = ImplicitRange<br />

233

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

Saved successfully!

Ooh no, something went wrong!