[Haskell-cafe] Re: (flawed?) benchmark : sort

Neil Mitchell ndmitchell at gmail.com
Mon Mar 10 07:28:36 EDT 2008


>  > instance Ord Foo where
>  >     compare (Foo a _) (Foo b _) = compare a b
>  I would consider such an Ord instance to be hopelessly broken, and I
>  don't think it's the responsibility of authors of functions with Ord
>  constraints in their sigs (such as sort) to consider such possibilities
>  or specify and control the behaviour of their behaviour for such
>  instances. Trying to do this is what leads to horrors such as the "left
>  biasing" of Data.Map (for example).

The sort in Haskell is specified to be "stable". What that means is
that the above ord relation is fine. The above ordering observes all
the necessary mathematical definitions of ordering, assuming an Eq of:

instance Eq Foo where
    (==) (Foo a _) (Foo b _) = (==) a b

>  Unfortunately the Haskell standards don't currently specify sane laws
>  for Eq and Ord class instances, but they should. Otherwise knowing a
>  type is an instance of Ord tells me nothing that I can rely on.

Please give the sane law that this ordering violates. I can't see any!

What if I had made the definition of Foo:

data Foo = Foo Int (Int -> Int)

Now, is the only possible answer that any Ord instance for Foo is wrong?



More information about the Haskell-Cafe mailing list