4 ms·
Yes, and now try this: import Debug.Trace qsort [] = [] qsort (x:xs) = trace "(Called)" qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)
by ramchip 16y ago
Yes, and now try this:
import Debug.Trace
qsort [] = []
qsort (x:xs) = trace "(Called)" qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)
Prelude> qsort $! [1..100]
Problem is, both of these "cute implementations" would be unusable in practice. It's hard to find beautiful code in 'real world' problems.
- _pius 16y agoWhile I see the problem with this implementation of QuickSort, I don't agree that "it's hard to find beautiful code in 'real world' problems." I think most programmers have opportunities to write elegant code every day.