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.

left context whitespace operator fixity whitespace right context<br />

yes<br />

infix<br />

yes<br />

primary<br />

yes<br />

left encloser<br />

no<br />

no<br />

right encloser yes<br />

primary<br />

no<br />

infix<br />

no<br />

primary<br />

yes<br />

yes<br />

no<br />

no<br />

infix<br />

left encloser<br />

right encloser<br />

infix<br />

yes<br />

no<br />

yes<br />

no<br />

operator<br />

primary<br />

yes error (right encloser)<br />

no<br />

right encloser<br />

, ; right encloser<br />

primary<br />

yes<br />

infix<br />

no<br />

right encloser<br />

line break<br />

operator<br />

error (left encloser) yes<br />

left encloser<br />

no<br />

primary<br />

operator<br />

error (left encloser) yes<br />

left encloser<br />

no<br />

operator<br />

operator error (nofix) , ; right encloser<br />

operator error (nofix) line break<br />

, ; left encloser left encloser primary<br />

, ; left encloser left encloser operator<br />

, ; left encloser nofix , ; right encloser<br />

, ; left encloser error (left encloser) line break<br />

Figure 16.2: Operator Fixity (II)<br />

16.4 Chained and Multifix Operators<br />

Certain infix mathematical operators that are traditionally regarded as relational operators, delivering boolean results,<br />

may be chained. For example, an expression such as A ⊆ B ⊂ C ⊆ D is treated as being equivalent to<br />

(A ⊆ B) ∧ (B ⊂ C) ∧ (C ⊆ D) except that the expressions B and C are evaluated only once (which matters only if<br />

they have side effects such as writes or input/output actions). <strong>Fortress</strong> restricts such chaining to operators of the same<br />

kind and having the same sense of monotonicity; for example, neither A ⊆ B ≤ C nor A ⊆ B ⊃ C is permitted.<br />

Equivalence operators may be mixed into a chain; for example, one may write A ⊆ B = C ⊆ D . This transformation<br />

is done before type checking. In particular, it is done even though these operators do not return boolean values, and<br />

the resulting expression is checked for type correctness. (See Section F.4 for a detailed description of which operators<br />

may be chained.)<br />

Any infix operator that does not chain may be treated as multifix. If n − 1 occurrences of the same operator separate<br />

n operands where n ≥ 3, then the compiler first checks to see whether there is a definition for that operator that will<br />

accept n arguments. If so, that definition is used; if not, then the operator is treated as left-associative and the compiler<br />

looks for a two-argument definition for the operator to use for each occurrence. As an example, the cartesian product<br />

S 1 × S 2 × · · · × S n of n sets may usefully be defined as a multifix operator, but ordinary addition p + q + r + s is<br />

normally treated as ((p + q) + r) + s .<br />

16.5 Enclosing Operators<br />

<strong>The</strong>se operators are always used in pairs as enclosing operators:<br />

(/ /) (\ \)<br />

129

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

Saved successfully!

Ooh no, something went wrong!