Difference between revisions of "Talk:Introduction"

From HaskellWiki
Jump to navigation Jump to search
m
(improved Haskell qsort code moved here from main page)
Line 1: Line 1:
 
 
Added the quote by Graham Klyne.
 
Added the quote by Graham Klyne.
   
Line 31: Line 30:
   
 
--[[User:Tsingi|Tsingi]] 11:08, 28 June 2010 (UTC)
 
--[[User:Tsingi|Tsingi]] 11:08, 28 June 2010 (UTC)
  +
  +
Although visually appealing, the Haskell quicksort code has the unfortunate property of doubly traversing the input list. This can be remedied with Bird's proposed
  +
  +
<haskell>
  +
qsort [] = []
  +
qsort (x:xs) = part xs ([],[])
  +
where
  +
part [] (a,b) = qsort a ++ x : qsort b
  +
part (y:ys) (a,b) = part ys $ if y<x then (y:a,b) else (a,y:b)
  +
</haskell>
  +
  +
Or, to keep it stable,
  +
<haskell>
  +
qsort (x:xs) = part xs (\(a,b)-> qsort a ++ x : qsort b)
  +
where
  +
part [] k = k ([],[])
  +
part (y:ys) k = part ys $ if y<x then (k.first(y:)) else (k.second(y:))
  +
</haskell>
  +
  +
But that's besides the point, so I removed it from the main page to here.

Revision as of 00:55, 26 September 2010

Added the quote by Graham Klyne.

Over the years I've received numerous complaints about the quicksort example. But none of the complainers sent me anything better so it's still here. Anyone want to come up with a better example?

--John Peterson 00:39, 26 January 2006 (UTC)

Perhaps an in-place quicksort? —Ashley Y 04:24, 26 January 2006 (UTC)
If you want to offer "proof" that functional programming is a good idea, starting out with an invalid example pretty much wipes out your credibility. Taking the quicksort example offered, you are saying that if memory and CPU use do not matter ... but they very often do (certainly for large sort operations). Reading up on Haskell looks too much like a waste of time. Why the equivalent quicksort code in Haskell is larger than the C code requires an explanation as to why this is a good idea - and is not suitable material for the introduction. --PrestonBannister 01:51, 12 August 2008 (UTC)
The good idea here is that the algorithm becomes rather obvious when presented in Haskell. dons 04:45, 12 August 2008 (UTC)
Change the C to mergesort? Because that really is what the Haskell code does. (Okay, sure, it's a funny 3-way, bottom-up, lazy mergesort. Still.) -- AaronDenney 19:55, 10 July 2007 (UTC)
Eh? The defining property of quicksort is that the diving phase is elaborate (filter < and >) but that the conquer phase is simple (list concatenation). For mergesort, it's the other way round. apfeλmus 10:51, 11 December 2007 (UTC)

What is this about Haskell being in 2nd place behind C (gcc) in the computer language shootout, the link provided shows it to be 13th (and 12th on the previous benchmark, even though it does proportionally worst). You're right about functional languages doing well though: Clean, OCaml and MLton indeed occupy positions 6,9,11. --Noegenesis 12:01, 28 August 2007 (UTC)

It was in 2nd place when the article was written, since then benchmarks and programs have changed. dons 00:17, 12 December 2007 (UTC)
Update, mid-2008, the rankings have stabilised with Haskell in 8th, behind C, C++, D and friends. The shootout continues to be a moving target. dons 04:45, 12 August 2008 (UTC)

Most functional languages, and Haskell in particular, are strongly typed, eliminating a huge class of easy-to-make errors at compile time. This sentence confuses strong and static typing. MichalPalka 00:11, 2 December 2007 (UTC)

I created a login account to specifically complain about the qsort example.

All it proves is that you can write your own, or use the standard c lib implementation. So, any programmer who knows c reading this sees it as a Steve Jobs style sales pitch. Developers don't like being lied to, I'd suggest you dump that sales approach for one that is honest, you've lost me.

--Tsingi 11:08, 28 June 2010 (UTC)

Although visually appealing, the Haskell quicksort code has the unfortunate property of doubly traversing the input list. This can be remedied with Bird's proposed

qsort []     = [] 
qsort (x:xs) = part xs ([],[])
  where
    part []     (a,b) = qsort a ++ x : qsort b
    part (y:ys) (a,b) = part ys $ if y<x then (y:a,b) else (a,y:b)

Or, to keep it stable,

qsort (x:xs) = part xs (\(a,b)-> qsort a ++ x : qsort b)
  where
    part []     k = k ([],[])
    part (y:ys) k = part ys $ if y<x then (k.first(y:)) else (k.second(y:))

But that's besides the point, so I removed it from the main page to here.