The tutorial defines:

quicksort  []    =  []
quicksort (x:xs) =  quicksort [y | y <- xs, y<x ] ++ [x] ++ quicksort [y | y <- xs, 
y>=x]

This code strikes me as twice as slow as it could be because it seems to 
requires two loops through the list on each recursive call.

Is quicksort defined this way because Haskell compilers know how to
consolidate the two list comprehensions into one? 

If not, where would I find the correct definition of qsort in haskell? 

In principle one could write one-pass code which generates tuples, but 
my instinct is that such code would be inelegant and hard to read.
I figure there must be a better way.

-Alex-

PS thanks to all for the explanation of the state of haskell.  it was very
informative.

___________________________________________________________________
S. Alexander Jacobson                   i2x Media  
1-212-697-0184 voice                    1-212-697-1427 fax

[There's various Haskell formulations of quicksort floating about. A
 generally popular one is Lennart's (++)-free version, which is
 included with HBC and GHC (at least.) -moderator]


Reply via email to