[email@example.com: Re: [GHC] #1218: Add sortNub and sortNubBy
duncan.coutts at worc.ox.ac.uk
Wed Mar 21 07:29:32 EDT 2007
On Wed, 2007-03-21 at 11:48 +0100, Bertram Felgenhauer wrote:
> Duncan Coutts wrote:
> > So can anyone break this hypothesis?
> > nub . sort = map head . group . sort
> Just make Eq and Ord instances that are completely unrelated, say
I had to compile the code and go thorough it to convince myself, but yes
as you say I'd fallen into the trap of 'believing' <= and == etc. I was
assuming that sort would put 'equal' elements next to each other in the
result but of course with compare x y == EQ not being the same as x == y
that's not the case. Sigh.
Thanks for the example.
I want type classes with real property conditions. I don't mind if
they're checked or not, but I want to be able to break people's code if
they don't obey the properties and optimise the code for the rest of us.
class Ord a => OrdReallyTruely a where
then I want to use ghc rules that match on the subset of Ord types that
are instances of OrdReallyTruely and be able to do the appropriate
forall (xs :: OrdReallyTruely a => [a]).
nub (sort xs) = map head (group (sort xs))
More information about the Libraries