Quick Sort Algorithm

Hi folks qSort (x:xs) = qSort smaller ++ [x] ++ qSort larger where smaller = [a | a . xs, a x ] larger = [b | b . xs, b > x ] Any idea why I can't get this to work? Thanks, Paul

What if the list is empty? You should take into account even this situation. Dusan PR Stanley wrote:
Hi folks qSort (x:xs) = qSort smaller ++ [x] ++ qSort larger where smaller = [a | a . xs, a x ] larger = [b | b . xs, b > x ] Any idea why I can't get this to work? Thanks, Paul
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Yes, sorry, I missed the firt line of the algorithm when I was pasting it into the email. Okay qSort [] = [x] -- and even qSort [x] = x The code fragment below still doesn't work.
qSort (x:xs) = qSort smaller ++ [x] ++ qSort larger where smaller = [a | a . xs, a x ] larger = [b | b . xs, b > x ]
Cheers Paul

Well, I don't know if it is by encoding of letters in your e-mail, but what do you expect that [a | a . xs, a x ] would do? Dusan PR Stanley wrote:
Yes, sorry, I missed the firt line of the algorithm when I was pasting it into the email. Okay qSort [] = [x] -- and even qSort [x] = x The code fragment below still doesn't work.
qSort (x:xs) = qSort smaller ++ [x] ++ qSort larger where smaller = [a | a . xs, a x ] larger = [b | b . xs, b > x ]
Cheers Paul
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Well, actually, this was scanned from a book but the OCR process wasn't 100% effective. So, I was hoping the list would easily identify and replace the erronious characters. Thanks for trying, anyway. Paul At 20:46 17/05/2007, you wrote:
Well, I don't know if it is by encoding of letters in your e-mail, but what do you expect that [a | a . xs, a x ] would do?
Dusan
PR Stanley wrote:
Yes, sorry, I missed the firt line of the algorithm when I was pasting it into the email. Okay qSort [] = [x] -- and even qSort [x] = x The code fragment below still doesn't work.
qSort (x:xs) = qSort smaller ++ [x] ++ qSort larger where smaller = [a | a . xs, a x ] larger = [b | b . xs, b > x ]
Cheers Paul
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

PR Stanley wrote:
Well, actually, this was scanned from a book but the OCR process wasn't 100% effective. So, I was hoping the list would easily identify and replace the erronious characters. Thanks for trying, anyway. Paul
...would it not be faster to pick up the book and check what the OCR got wrong? ;-) Anyway, I'm going to go out on a limb and suggest
smaller = [a | a <- xs, a <= x] larger = [a | a <- xs, a > x]

You could also look at
http://haskell.org/haskellwiki/Introduction#Quicksort_in_Haskell
if the algorithm is all you're interested in, and not the particular
implementation.
On 5/17/07, Andrew Coppin
PR Stanley wrote:
Well, actually, this was scanned from a book but the OCR process wasn't 100% effective. So, I was hoping the list would easily identify and replace the erronious characters. Thanks for trying, anyway. Paul
...would it not be faster to pick up the book and check what the OCR got wrong? ;-)
Anyway, I'm going to go out on a limb and suggest
smaller = [a | a <- xs, a <= x] larger = [a | a <- xs, a > x]
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Well, actually, this was scanned from a book but the OCR process wasn't 100% effective. So, I was hoping the list would easily identify and replace the erronious characters. Thanks for trying, anyway. Paul
...would it not be faster to pick up the book and check what the OCR got wrong? ;-) No, Mr. smarty pants, I can't. I'll leave you to work out why I rely on a scanner and an OCR engine for reading printed materials. *smile* Paul
Anyway, I'm going to go out on a limb and suggest
smaller = [a | a <- xs, a <= x] larger = [a | a <- xs, a > x]
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

PR Stanley
No, Mr. smarty pants, I can't. I'll leave you to work out why I rely on a scanner and an OCR engine for reading printed materials. *smile*
Ah. Well, given your original question ("why does this code not work?") it was probably a reasonable assumption that you had written it yourself, and the problem you wanted help with was understanding the semantics of what you had written. Whereas if you had phrased your question initially more like "I am having difficulty reading/using this OCR'd version of someone else's code", the responses could perhaps have been more helpful more quickly. Anyway, the corrected code snippet follows: qSort (x:xs) = qSort smaller ++ [x] ++ qSort larger where smaller = [a | a <- xs, a <= x ] larger = [b | b <- xs, b > x ] If your reading software can be trained to convert sequences of symbols into phrases, then "++" might be pronounced as "append", and "<-" as "drawn from". Regards, Malcolm

Dear Sir, At the risk of seeming a little pedantic let me remind you that Andrew's remark was in reply to the following message: start message Well, actually, this was scanned from a book but the OCR process wasn't 100% effective. So, I was hoping the list would easily identify and replace the erronious characters. Thanks for trying, anyway. Paul end message If that isn't clear enough then ... Regards, Paul
PR Stanley
wrote: No, Mr. smarty pants, I can't. I'll leave you to work out why I rely on a scanner and an OCR engine for reading printed materials. *smile*
Ah. Well, given your original question ("why does this code not work?") it was probably a reasonable assumption that you had written it yourself, and the problem you wanted help with was understanding the semantics of what you had written. Whereas if you had phrased your question initially more like "I am having difficulty reading/using this OCR'd version of someone else's code", the responses could perhaps have been more helpful more quickly.
Anyway, the corrected code snippet follows:
qSort (x:xs) = qSort smaller ++ [x] ++ qSort larger where smaller = [a | a <- xs, a <= x ] larger = [b | b <- xs, b > x ]
If your reading software can be trained to convert sequences of symbols into phrases, then "++" might be pronounced as "append", and "<-" as "drawn from".
Regards, Malcolm _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (5)
-
Andrew Coppin
-
Andrew Wagner
-
Dušan Kolář
-
Malcolm Wallace
-
PR Stanley