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.

Chapter 37<br />

Algebraic Constraints<br />

<strong>The</strong> traits in this component are used to describe properties of traits and their associated operators. <strong>The</strong>se traits provide<br />

very few concrete methods, but specify abstract methods and property declarations. For this reason, the complete<br />

code for these traits is presented here, rather than just the APIs.<br />

37.1 Predicates and Equivalence Relations<br />

A predicate is an operator that produces a boolean result. A binary predicate may be identified with a mathematical<br />

relation, where the predicate returns true in exactly those cases that its two operands satisfy the relation; therefore we<br />

use the mathematical terminology usually associated with relations to describe the properties of binary predicates.<br />

trait UnaryPredicateT extends UnaryPredicateT, ∼,opr ∼<br />

opr ∼(self): Boolean<br />

end<br />

A unary predicate is a prefix operator that takes one argument and returns a boolean value (true or false ). Note that<br />

∼ is a static parameter, used here as a “variable” name for an operator.<br />

trait BinaryPredicateT extends BinaryPredicateT, ∼,opr ∼<br />

opr ∼(self,other: T): Boolean<br />

end<br />

A binary predicate is an infix operator that takes two arguments and returns a boolean value. Thus, for example, any<br />

trait T that extends BinaryPredicateT, ⊏ necessarily has an infix method for the operator ⊏ , and that operator<br />

returns a boolean value.<br />

trait ReflexiveT extends ReflexiveT, ∼,opr ∼<br />

extends { BinaryPredicateT, ∼ }<br />

property ∀(a:T) (a ∼ a)<br />

end<br />

A reflexive predicate always returns true when its operands are the same. Because this fact is expressed as a property<br />

declaration, the behavior of such an operator can be checked for correctness by unit testing.<br />

trait IrreflexiveT extends IrreflexiveT, ∼,opr ∼<br />

extends { BinaryPredicateT, ∼ }<br />

246

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

Saved successfully!

Ooh no, something went wrong!