I found the following implementation of quicksort in the book titled Learn You Haskell.
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]
in smallerSorted ++ [x] ++ biggerSorted
My question is, doesn't this undermine the efficiency of quicksort given that
- The ++ operation is rather expensive
- List comprehension is used to construct the two sublists?