[Haskell-cafe] Ord instance of Bool (Was: Unnecessarily strict implementations)

Henning Thielemann lemming at henning-thielemann.de
Fri Sep 3 06:13:01 EDT 2010


Henning Thielemann schrieb:
> Ivan Lazar Miljenovic schrieb:
>> On 3 September 2010 04:57, Arie Peterson <ariep at xs4all.nl> wrote:
>>> On Thu, 2 Sep 2010 19:30:17 +0200, Daniel Fischer
>>> <daniel.is.fischer at web.de> wrote:
>>>> Why would one consider using Ord for Map an abuse?
>>>> A kludge, for performance reasons, but an abuse?
>>> Because it forces one to declare Ord instances for types which have no
>>> natural ordering. It is useful to *not* have such instances, in order to
>>> catch programming errors.
>> What precisely do you mean by natural ordering?
>
> E.g. I wanted to have a Set of Gaussian (complex) integers, but I did
> not want to define an Ord instance for them, because writing
>   a < (b :: Gaussian)
> is a bug with high probability.

I like to answer in advance to the objections that might come. :-)

You might object, that it is seldom, that someone intentionally writes
(a<b) if 'a' and 'b' are complex numbers. However imagine 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 (<) has to be applied to results of 'abs',
'realPart' or other functions that yield a real.


More information about the Haskell-Cafe mailing list