[Haskell-cafe] k-minima in Haskell

Thorkil Naur naur at post11.tele.dk
Fri Apr 13 09:08:15 EDT 2007


Hello,

My Hugs tells me this:

Prelude> let sort [] = []; sort l@(x:_) = filter (<x) l ++ filter (==x) l ++ 
filter (>x) l in sort [1,3,2]
[1,3,2]
Prelude>

So, no, this is not a working sorting function. Inserting the "few missing 
recursive calls":

Prelude> let sort [] = []; sort l@(x:_) = sort ( filter (<x) l ) ++ filter 
(==x) l ++ sort ( filter (>x) l ) in sort [1,3,2]
[1,2,3]
Prelude>

Best regards
Thorkil
On Friday 13 April 2007 11:38, Thomas Hartman wrote:
> And for reference, here is again stefan's "stable" quicksort from his
> earlier post.
> 
> "
> sort [] = []
> sort l@(x:_) = filter (<x) l ++ filter (==x) l ++ filter (>x) l
> 
> (A stable quicksort, btw)
> "
> 
> This is the code whose legitimacy I am requesting confirmation of.
> 
> 2007/4/13, Thomas Hartman <tphyahoo at gmail.com>:
> > > > You may be missing a few recursive calls there :-)
> > >
> > > Indeed.
> >
> ...


More information about the Haskell-Cafe mailing list