Last active
February 23, 2018 16:05
-
-
Save jmackie/8950c47716823b9344815fdf208412ac to your computer and use it in GitHub Desktop.
Quicksort, Idris style
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 Main | |
-- data List a = (::) a (List a) | Nil | |
quicksort : Ord a => List a -> List a | |
quicksort [] = [] | |
quicksort (x :: xs) = (sort lower) ++ [x] ++ (sort upper) | |
where lower = filter (<x) xs | |
upper = filter (>=x) xs | |
main : IO () | |
main = traverse_ printLn | |
[ quicksort [3, 2, 1, 0, -1, -2, -3] | |
, quicksort [4, 2, 0, 1, 3, 5] | |
, quicksort [2, 1] | |
, quicksort [1] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment