[Haskell-beginners] Function result being inversed
Xavier Shay
xavier-list at rhnh.net
Tue Jan 25 21:15:04 CET 2011
Thanks to all responses. Makes sense now. For the record I have ended up
with this:
mySort [] = []
mySort (h:t) =
f(<=) ++ [h] ++ f(>)
where f x = mySort (filter (not . x h) t)
I have a feeling I may be able to make the following work with some sort
of type declaration but I haven't really learned much about them yet so
I will revisit later. (At the moment it does not compile.)
mySort [] = []
mySort (h:t) =
f(<=) ++ [h] ++ f(>)
where f x = mySort (filter (h x) t)
Cheers,
Xavier
On 26/01/11 7:00 AM, Xavier Shay wrote:
> Hello,
> I am confused by the following code.
> I would expect results of True, False.
>
> $ ghci
> *Main> let f x = x 4
> *Main> f(<) 3
> False
> *Main> f(<) 5
> True
>
> This came about because I was trying to refactor a sort function I wrote:
>
> mySort [] = []
> mySort (h:t) =
> (f (<= h)) ++ [h] ++ (f (> h))
> where f x = mySort (filter x t)
>
> I came up with this, which appears to work, though the comparison
> operators are backwards.
>
> mySort [] = []
> mySort (h:t) =
> f(>) ++ [h] ++ f(<=)
> where f x = mySort (filter (x h) t)
>
> Cheers,
> Xavier
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
More information about the Beginners
mailing list