Created
December 10, 2019 09:57
-
-
Save BalzGuenat/52075420d8641737dec4ab343e8a6c2d to your computer and use it in GitHub Desktop.
Short Mergesort in Haskell
This file contains hidden or 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
msort :: Ord a => [a] -> [a] | |
msort [] = [] | |
msort [a] = [a] | |
msort as = let half = div (length as) 2; merge [] ys = ys; merge xs [] = xs | |
merge (x:xs) (y:ys) = if x <= y then x:merge xs (y:ys) else y:merge (x:xs) ys | |
in merge (msort $ take half as) (msort $ drop half as) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment