Created
October 17, 2012 14:09
-
-
Save anonymous/3905696 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.List as List | |
sort cmp lst = mergeMany (map return lst) [] | |
where | |
merge (xs@(x:xs')) (ys@(y:ys')) !zs = | |
case y `cmp` x of | |
LT -> merge xs ys' (y:zs) | |
_ -> merge xs' ys (x:zs) | |
merge xs ys zs = reverseAppend zs $! xs ++ ys | |
mergeMany [] [] = [] | |
mergeMany [xs] [] = xs | |
mergeMany [] [ys] = ys | |
mergeMany (a:b:xss) yss = mergeMany xss $! merge a b [] : yss | |
mergeMany xss yss = mergeMany (xss ++ yss) [] | |
reverseAppend xs ys = go xs ys | |
where | |
go [] ys = ys | |
go (x:xs) ys = go xs $! x:ys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment