[Haskell-cafe] Unnecessarily strict implementations

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

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.

>> A separate type class for types which can be ordered in some (possibly
>> arbitrary) way, for use in Data.Map, would remedy this.
> Sure... except that the way Data.Map and Data.Set are implemented is
> by a binary tree, and you typically want some kind of ordering for
> those.
> How is a type class that represents arbitrary ordering any different
> from what we already have?  The notation might not be the best if you
> consider the ordering to be arbitrary, but what else would you use?
> "isArbitrarilyBefore :: (ArbitraryOrdering a) => a -> a -> Bool" ?

Yes, something this way. (<) suggests a notion of magnitude for me,
which some orderings do not have.

More information about the Haskell-Cafe mailing list