Skip to content

Instantly share code, notes, and snippets.

@KirinDave
Last active March 9, 2018 02:18
Show Gist options
  • Save KirinDave/3d88cffcb1f7a9f6b9f9b4d9d5e2eb96 to your computer and use it in GitHub Desktop.
Save KirinDave/3d88cffcb1f7a9f6b9f9b4d9d5e2eb96 to your computer and use it in GitHub Desktop.
mergeSort :: Ord a => [a] -> [a]
mergeSort = hylo alg coalg where
alg EmptyF = []
alg (LeafF c) = [c]
alg (NodeF l r) = merge l r
coalg [] = EmptyF
coalg [x] = LeafF x
coalg xs = NodeF l r where
(l, r) = splitAt (length xs `div` 2) xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment