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.

trait PartialOrderOperatorsT extends PartialOrderOperatorsT, ≺, , , ≻,CMP,<br />

opr ≺,opr ,opr ,opr ≻,opr CMP<br />

extends { StrictPartialOrderT, ≺, PartialOrderT, ,<br />

PartialOrderT, , StrictPartialOrderT, ≻ }<br />

opr CMP(self,other:T): Comparison<br />

opr ≺(self,other: T): Boolean = (aCMP b) = LessThan<br />

opr (self,other: T): Boolean = (aCMP b) = LessThan ∨ (aCMP b) = EqualTo<br />

opr =(self,other: T): Boolean = (aCMP b) = EqualTo<br />

opr (self,other: T): Boolean = (aCMP b) = GreaterThan ∨ (aCMP b) = EqualTo<br />

opr ≻(self,other: T): Boolean = (aCMP b) = GreaterThan<br />

property ∀(a:T, b: T) ((aCMP b) = LessThan) ↔ ((bCMP a) = GreaterThan)<br />

property ∀(a:T, b: T) ((aCMP b) = EqualTo) ↔ ((bCMP a) = EqualTo)<br />

property ∀(a:T, b: T) ((aCMP b) = Unordered) ↔ ((bCMP a) = Unordered)<br />

property ∀(a:T, b: T) (a ≺ b) ↔ ((aCMP b) = LessThan)<br />

property ∀(a:T, b: T) (a b) ↔ ((aCMP b) = LessThan ∨ (aCMP b) = EqualTo)<br />

property ∀(a:T, b: T) (a = b) ↔ ((aCMP b) = EqualTo)<br />

property ∀(a:T, b: T) (a b) ↔ ((aCMP b) = GreaterThan ∨ (aCMP b) = EqualTo)<br />

property ∀(a:T, b: T) (a ≻ b) ↔ ((aCMP b) = GreaterThan)<br />

end<br />

For practical programming, we assume that partial order operators come in groups of five: a “less than” predicate, a<br />

“less than or equal to” predicate, a “greater than or equal to” predicate, a “greater than” predicate, and a “comparison”<br />

operator that returns one of the four values LessThan, EqualTo, GreaterThan, and Unordered. <strong>The</strong> trait<br />

PartialOrderOperators declares such a set of five operators and describes the necessary algebraic constraints among<br />

them and the equality predicate = . It also provides default definitions for the predicates (including = ) in terms of<br />

the comparison operator.<br />

trait TotalOrderOperatorsT extends TotalOrderOperatorsT, ≺, , , ≻,CMP,<br />

opr ≺,opr ,opr ,opr ≻,opr CMP<br />

extends { PartialOrderOperatorsT, ≺, , , ≻,CMP,<br />

StrictTotalOrderT, ≺, TotalOrderT, ,<br />

TotalOrderT, , StrictTotalOrderT, ≻ }<br />

opr CMP(self,other:T): TotalComparison<br />

end<br />

Total order operators likewise come in groups of five: a “less than” predicate, a “less than or equal to” predicate, a<br />

“greater than or equal to” predicate, a “greater than” predicate, and a “comparison” operator that returns one of the<br />

three values LessThan, EqualTo, and GreaterThan. <strong>The</strong> trait TotalOrderOperators declares such a set of five<br />

operators and describes the necessary algebraic constraints among them and the equality predicate = . For a total<br />

order, the comparison operator CMP never returns Unordered.<br />

trait PartialOrderBasedOnLET extends PartialOrderBasedOnLET, ≺, , , ≻,CMP,<br />

opr ≺,opr ,opr ,opr ≻,opr CMP<br />

extends { PartialOrderOperatorsT, ≺, , , ≻,CMP }<br />

opr CMP(self,other:T): Comparison =<br />

if a b then<br />

if b a then EqualTo else LessThan end<br />

else<br />

if b a then GreaterThan else Unordered end<br />

end<br />

opr ≺(self,other: T): Boolean = (self other) ∧ ¬(other self)<br />

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

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

249

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

Saved successfully!

Ooh no, something went wrong!