[Haskell-beginners] points-free problem

I. J. Kennedy jack at realmode.com
Fri Nov 20 17:22:08 EST 2009

I know I'm going to kick myself when the answer is revealed by one of
you kind folks, but after staring at this a while I just can't figure
out what's going on. The compiler (ghci) is trying so hard to tell me
what's wrong, but I am failing to understand. I thought for the most
part one could take a function definition like

 f x  = (blah blah blah) x

and turn it into points-free style by

 f = (blah blah blah)

But from the dialog below, my assumption is incorrect.

I. J. Kennedy

> sortBy (compare `on` fst) [(2,3),(0,1),(1,5)]   -- test a little sort expression
> let sortpairs xss = sortBy (compare `on` fst) xss   -- make it into a function
> :t sortpairs
sortpairs :: (Ord a) => [(a, b)] -> [(a, b)]
> sortpairs [(2,3),(0,1),(1,5)]
> let sortpairs = sortBy (compare `on` fst)    -- points-free style
> sortpairs [(2,3),(0,1),(1,5)]
    No instance for (Num ())
      arising from the literal `1' at <interactive>:1:24
    Possible fix: add an instance declaration for (Num ())
    In the expression: 1
    In the expression: (1, 5)
    In the first argument of `sortpairs', namely
        `[(2, 3), (0, 1), (1, 5)]'
> :t sortpairs
sortpairs :: [((), b)] -> [((), b)]      --  what?!

More information about the Beginners mailing list