Skip to content

Instantly share code, notes, and snippets.

@jmackie
Last active February 23, 2018 16:05
Show Gist options
  • Save jmackie/8950c47716823b9344815fdf208412ac to your computer and use it in GitHub Desktop.
Save jmackie/8950c47716823b9344815fdf208412ac to your computer and use it in GitHub Desktop.
Quicksort, Idris style
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