[Haskell-beginners] Function result being inversed

Daniel Fischer daniel.is.fischer at googlemail.com
Tue Jan 25 21:21:22 CET 2011


On Tuesday 25 January 2011 21:15:04, Xavier Shay wrote:
> 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)

Well, h is not a function, so (h x) isn't well formed.
You want a left operator section there, so you have to make the function x 
infix:

    where f x = mySort (filter (h `x`) t)

Backticks turn ordinary prefix functions into infix functions,

a `mod` b === mod a b

>
> Cheers,
> Xavier



More information about the Beginners mailing list