[Haskell-cafe] Re: (flawed?) benchmark : sort
Neil Mitchell
ndmitchell at gmail.com
Mon Mar 10 04:27:42 EDT 2008
Hi
> 2) What does it do with duplicate elements in the list? I expect it deletes
> them. To avoid this, you'd need to use something like fromListWith, keeping
> track of how many duplicates there are, and expanding at the end.
That would be wrong. Consider:
data Foo = Foo Int Int
instance Ord Foo where
compare (Foo a _) (Foo b _) = compare a b
sort [Foo 1 2, Foo 1 -2] must return the original list back, in that
order. You cannot delete things and duplicate them later. To guarantee
the ordering you must also do other stuff.
Thanks
Neil
More information about the Haskell-Cafe
mailing list