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.

extends { UnaryOperatorT, ⊙, BinaryPredicateT, ≃ }<br />

property ∀(a:T, a ′ : T) (a ≃ a ′ ) →:(⊙a) ≃ (⊙a ′ )<br />

end<br />

This peculiarly spiffy trait states that the unary operator ⊙ is consistent under substitutions described by the relation<br />

≃ (which is typically, but not always, an equivalence relation); that is, the result produced by ⊙ is unchanged if its<br />

argument is replaced by some other value that is equivalent.<br />

trait BinaryOperatorSubstitutionLawsT extends BinaryOperatorSubstitutionLawsT, ⊙, =,<br />

opr ⊙,opr ≃<br />

extends { BinaryOperatorT, ⊙, BinaryPredicateT, ≃ }<br />

property ∀(a:T, a ′ : T) (a ≃ a ′ ) →: ∀(b: T) (a ⊙ b) ≃ (a ′ ⊙ b)<br />

property ∀(b: T, b ′ : T) (b ≃ b ′ ) →: ∀(a: T) (a ⊙ b) ≃ (a ⊙ b ′ )<br />

end<br />

This equally spiffy trait states that the binary operator ⊙ is consistent under substitutions described by the relation ≃<br />

(which is typically, but not always, an equivalence relation); that is, the result produced by ⊙ is unchanged if either<br />

argument is replaced by some other value that is equivalent. (It is then easy to prove that the result is unchanged even<br />

when both arguments are replaced by equivalent values.)<br />

37.4 Monoids, Groups, Rings, and Fields<br />

trait ApproximateMonoidT extends ApproximateMonoidT, ⊙, ≈,opr ⊙,opr ≈<br />

extends { ApproximatelyAssociativeT, ⊙, ≈, HasIdentityT, ⊙ }<br />

end<br />

An approximate monoid is a set of values with an approximately associative binary operator ⊙ that has an identity.<br />

For example, floating-point multiplication has identity 1 and is approximately associative.<br />

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

extends { ApproximateMonoidT, ⊙, =, AssociativeT, ⊙ }<br />

end<br />

A monoid is a set of values with an associative binary operator ⊙ that has an identity. For example, trait String<br />

extends MonoidString, ‖ where ‖ is the string concatenation operator. Note that string concatenation is associative<br />

but not commutative and that the empty string is the identity for string concatenation, so coercing Identity ‖, to<br />

type String produces the empty string.<br />

trait ApproximateCommutativeMonoid T extends ApproximateCommutativeMonoidT, ⊕, ≈,<br />

opr ⊕,opr ≈<br />

extends { ApproximateMonoidT, ⊕, ≈, ApproximatelyCommutativeT, ⊕, ≈ }<br />

end<br />

An approximate commutative monoid is an approximate monoid whose binary operator is also approximately commutative.<br />

For example, floating-point multiplication has identity 1 and is approximately associative and also approximately<br />

(indeed, exactly) commutative.<br />

trait CommutativeMonoidT extends CommutativeMonoidT, ⊕,opr ⊕<br />

extends { ApproximateCommutativeMonoidT, ⊕, =, MonoidT, ⊕, CommutativeT, ⊕ }<br />

end<br />

A commutative monoid is a monoid whose binary operator is also commutative. For example, the operator ∧ on<br />

boolean values is associative and commutative and has identity true ; likewise, the operator ∨ on boolean values is<br />

associative and commutative and has identity false .<br />

256

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

Saved successfully!

Ooh no, something went wrong!