summaryrefslogtreecommitdiff
path: root/progs/demo/quicksort.hs
diff options
context:
space:
mode:
Diffstat (limited to 'progs/demo/quicksort.hs')
-rw-r--r--progs/demo/quicksort.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/progs/demo/quicksort.hs b/progs/demo/quicksort.hs
new file mode 100644
index 0000000..30b4ab4
--- /dev/null
+++ b/progs/demo/quicksort.hs
@@ -0,0 +1,13 @@
+-- Quick sort for Haskell.
+
+module Main where
+
+qs :: [Int] -> [Int]
+qs [] = []
+qs (a:as) = qs [x | x <- as, x <= a] ++ [a] ++ qs [x | x <- as, x > a]
+
+main =
+ appendChan stdout "Enter a list of integers separated by \",\"\n" abort $
+ readChan stdin abort $ \ input ->
+ appendChan stdout (show (qs (read ("[" ++ (head (lines input)) ++ "]"))))
+ abort done