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.

11.5 Operator and Identifier Parameters<br />

Syntax:<br />

StaticParam ::= opr Op<br />

| ident Id<br />

Static parameters may include one or more operator symbols and identifiers denoting method names. Syntactically,<br />

an operator parameter begins with the special reserved word opr followed by an operator symbol. An identifier<br />

parameter begins with the special reserved word ident followed by an identifier.<br />

Unlike other static parameters, operator and identifier parameters may be used in both type context and value context.<br />

<strong>The</strong> following example operator parameter ⊙ :<br />

trait UnaryOperatorT extends UnaryOperatorT, ⊙,opr ⊙<br />

opr ⊙(self): T<br />

end<br />

is declared as a static parameter of UnaryOperator, instantiated as a static argument, and declared as an operator<br />

method.<br />

Operator and identifier parameters may be freely intermixed with other static parameters. For example, the following<br />

trait HasLeftZeroes:<br />

trait HasLeftZeroesT extends HasLeftZeroesT, ⊙,isLeftZero,opr ⊙,ident isLeftZero<br />

extends { BinaryOperatorT, ⊙ }<br />

isLeftZero():Boolean<br />

property ∀(a:T, b: T) a.isLeftZero() →: ((a ⊙ b) = a)<br />

end<br />

is parameterized with a type parameter T , an operator parameter ⊙ , and an identifier parameter isLeftZero . Many<br />

interesting examples are described in Section 37.3.<br />

11.6 Where Clauses<br />

Syntax:<br />

Where ::= where { WhereClauseList }<br />

WhereClauseList ::= WhereClause ( , WhereClause) ∗<br />

WhereClause ::= Id Extends<br />

| TypeAlias<br />

| NatConstranint<br />

| IntConstranint<br />

| BoolConstraint<br />

| UnitConstraint<br />

| TypeRef coerces TypeRef<br />

| TypeRef widens TypeRef<br />

Static parameters may have constraints placed on them in a where clause. A where clause begins with the special<br />

reserved word where , followed by a sequence of static parameter constraints enclosed in braces { and } , and<br />

separated by commas.<br />

A where clause may introduce new static variables, i.e., identifiers for types and other static entities that may not<br />

be static parameters. We use the term where -clause variables to refer to static variables that are not also static<br />

parameters. <strong>The</strong> where -clause variables must be bound in a where clause.<br />

A static parameter constraint is one of the following forms:<br />

83

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

Saved successfully!

Ooh no, something went wrong!