Ord instance
From HaskellWiki
What is the meaning of theOrd
Ord
However opinions differ whether there shall be more in it:
- An instance may also suggest a notion of magnitudeOrd
- An instance may be free of any other associationOrd
Depending on these opinions we come to different conclusions
whether there should beOrd
Bool
Complex
a < b
a
b
Bool
Complex
Consider someone rewrites an algorithm for real numbers to complex numbers and he relies on the type system to catch all inconsistencies.
The field operations can remain the same, but(<)
abs
realPart
False < True
False
True
However there are also programming languages that represent "true" by -1, because this has bit pattern 1....1. The CPU has an instruction to fill a byte with the content of a flag and you can use this bit pattern for bitwise AND and OR operations. This makes that representation very efficient.
In such a language it isFalse > True
2 * fromEnum bool - 1
False
True
if-then-else
then porting a program between different representations of boolean values becomes error-prone.
However you like to work withSet
Set
Ord
See also
- Haskell-Cafe on Unnecessarily strict implementations
