Skip to content

Instantly share code, notes, and snippets.

@kazu-yamamoto
Created February 3, 2011 01:44
Show Gist options
  • Save kazu-yamamoto/808890 to your computer and use it in GitHub Desktop.
Save kazu-yamamoto/808890 to your computer and use it in GitHub Desktop.
module Merge where
merge :: (Ord a) => [a] -> [a] -> [a]
merge xs [] = xs
merge [] ys = ys
merge l@(x:xs) r@(y:ys)
| x < y = x: merge xs r
| otherwise = y: merge l ys
msort :: Ord a => [a] -> [a]
msort [] = []
msort [x] = [x]
msort xs = merge (msort left) (msort right)
where
n = length xs `div` 2
left = take n xs
right = drop n xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment