qsort [] = []
qsort (p:xs) = qsort lt ++ [p] ++ qsort gt
where (lt, gt) = partition' (\x -> x <= p) xs
-- lt = [x | x <- xs, x <= p]
-- gt = [x | x <- xs, x > p]
partition' _ [] = ([], [])
partition' f (x:xs)
| f x = ((x:accepted, rejected))
| otherwise = ((accepted, x:rejected))
where (accepted, rejected) = partition' f xs
main = do
print $ qsort [3,4,1,2]
print $ partition' odd [1,2,3,4]
To embed this project on your website, copy the following code and paste it into your website's HTML: