Created
February 3, 2011 01:44
-
-
Save kazu-yamamoto/808890 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
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