
On Mar 20, 2007, at 6:53 PM, Duncan Coutts wrote:
On Tue, 2007-03-20 at 14:11 +0100, Nils Anders Danielsson wrote:
On Tue, 20 Mar 2007, Duncan Coutts
wrote: H98 requires that Eq and Ord be equality classes and total orders
Does it? I was under the impression that a compiler can never assume that any laws hold of any user-defined instances (to do optimisations, for instance).
The report states the following:
"The Eq class provides equality (==) and inequality (/=) methods." "The Ord class is used for totally ordered datatypes."
I interpret this as being mere usage guidelines, and nothing more.
Aye.
Hmm, I've always taken these to be binding contracts. For example, do I get to assume either == or <= are transitive? But I admit this is at the level of writing libraries---so that, as another poster noted, I'm allowed to use a sort function which yields a different result (possibly _|_) if I don't obey the contract. But I'd often like my compiler to assume that <= is transitive... -Jan-Willem Maessen