I tried this version, > however.... >>> nsortBy cmp l = mergesort compare l > should be: > > nsortBy cmp l = mergesort cmp l > > Thanks Sorry, with this version I meant:
> nsort l = mergesort compare l > nsortBy cmp l = mergesort compare l > > mergesort :: (a -> a -> Ordering) -> [a] -> [a] > mergesort cmp = mergesort' cmp . map wrap > > mergesort' :: (a -> a -> Ordering) -> [[a]] -> [a] > mergesort' cmp [] = [] > mergesort' cmp [xs] = xs > mergesort' cmp xss = mergesort' cmp (merge_pairs cmp xss) > > merge_pairs :: (a -> a -> Ordering) -> [[a]] -> [[a]] > merge_pairs cmp [] = [] > merge_pairs cmp [xs] = [xs] > merge_pairs cmp (xs:ys:xss) = merge cmp xs ys : merge_pairs cmp xss > > 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 > LT -> x : merge cmp xs (y:ys) > EQ -> x : merge cmp xs ys > > wrap :: a -> [a] > wrap x = [x] > _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe