4 ms·
Quicksort looks significantly better in a functional style. Here's some Haskell, but it certainly doesn't use any Haskell-exclusive features: quicksort ::
by cheepin 12y ago
Quicksort looks significantly better in a functional style. Here's some Haskell, but it certainly doesn't use any Haskell-exclusive features:
quicksort :: Ord a => [a] -> [a]
quicksort [] = []
quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)
where
lesser = filter (< p) xs
greater = filter (>= p) xs
- Crito 12y agoDefinitely. Pointing to C++ as a mainstream language that is uglier than Java seems a bit like missing the point since it is basically the exception that proves the rule, but he did say "in any other mainstream language. Period." ;)
- loqi 12y agoWhen is quicksort not quicksort? When it's not in-place: http://augustss.blogspot.com/2007/08/quicksort-in-haskell-quicksort-is.html http://augustss.blogspot.com/2007/08/quicksort-in-haskell-qu... I love me some Haskell, but this particular example is kind of a bait-and-switch.