ghc-5.04 sort not stable?

Simon Marlow simonmar at microsoft.com
Mon Jul 22 09:45:14 EDT 2002


> The merge routine is not stable (in 
> fptools/libraries/base/Data/List.hs).
> Fix: replace
> 
> merge :: (a -> a -> Ordering) -> [a] -> [a] -> [a]
> merge cmp xs [] = xs
> merge cmp [] ys = ys
> merge cmp (x:xs) (y:ys)
>  = case x `cmp` y of
>         LT -> x : merge cmp    xs (y:ys)
>         _  -> y : merge cmp (x:xs)   ys
> 
> by
> 
> merge :: (a -> a -> Ordering) -> [a] -> [a] -> [a]
> merge cmp xs [] = xs
> merge cmp [] ys = ys
> merge cmp (x:xs) (y:ys)
>  = case x `cmp` y of
>         GT -> y : merge cmp (x:xs)   ys
>         _  -> x : merge cmp    xs (y:ys)

Committed, thanks.

Cheers,
	Simon



More information about the Glasgow-haskell-bugs mailing list