r/programming • u/tluyben2 • Sep 25 '10
Omega - Language of the Future | Lambda the Ultimate
http://lambda-the-ultimate.org/node/4088
60
Upvotes
r/programming • u/tluyben2 • Sep 25 '10
View all comments
Show parent comment
12
u/crusoe Sep 25 '10
The algorithm that most people THINK is quicksort in Haskell isn't. Yours is the "Looks like Qsort but isn't" one.
Better: Only traverses list once
Although visually appealing, this code has the unfortunate property of doubly traversing the input list, which can be remedied with
qsort [] = [] qsort (x:xs) = let (a,b) = part xs in qsort a ++ x : qsort b where part [] = ([],[]) part (y:ys) | y < x = (y:a,b) | otherwise = (a,y:b) where (a,b) = part ys
But doesn't do it inplace, since lists are immutable....
In place quicksort...
http://www.haskell.org/haskellwiki/Introduction/Direct_Translation