News for hackers. Stuff that matters.
Re:Three Beautiful Quicksorts by ola on Friday July 11, 2008 @12:11AM (#243238)
You're doing two filters with list comprehensions which you could switch with one span:

    quicksort (x:xs) = let (a, b) = span (< x) xs in (quicksort a) ++ [x] ++ (quicksort b)
Re:Three Beautiful Quicksorts by fallintothis on Friday July 11, 2008 @06:13AM (#243394)
You're doing two filters with list comprehensions which you could switch with one span:

    quicksort (x:xs) = let (a, b) = span (< x) xs in (quicksort a) ++ [x] ++ (quicksort b)
Actually, this is incorrect. span will split the list as soon as it finds the predicate to be false on an item, instead of finding the smaller elements of the whole list. So, for instance, if we try your function as in the following, we get improper results:

  > quicksort [1, 2, 3, 2, 1]
  [1,2,1,2,3]
  > quicksort [1, 2, 3, -2, -1]
  [1,2,-2,-1,3]
  > quicksort [1, 2, 3, -2, 0, -1]
  [1,2,-2,-1,0,3]
Re:Three Beautiful Quicksorts by ola on Friday July 11, 2008 @08:06AM (#243441)
Serves me right, should have tested the code before I submitted it. Just s/span/partition/ and it should work.