# points-free problem Classic List Threaded 4 messages Open this post in threaded view
|

## points-free problem

 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. Help? I. J. Kennedy > sortBy (compare `on` fst) [(2,3),(0,1),(1,5)] ? -- test a little sort expression [(0,1),(1,5),(2,3)] > 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)] [(0,1),(1,5),(2,3)] > let sortpairs = sortBy (compare `on` fst) ? ?-- points-free style > sortpairs [(2,3),(0,1),(1,5)] :1:24: ?? ?No instance for (Num ()) ?? ? ?arising from the literal `1' at :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?!
Open this post in threaded view
|

## points-free problem

 Am Freitag 20 November 2009 23:22:08 schrieb I. J. Kennedy: > 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. > Help? > > I. J. Kennedy Monomorphism restriction. By that, if you bind f via f = (blah blah blah) and don't give a type signature, f gets a monomorphic type. Dreadful details in the report, section 4.5.(?) Put ":set -XNoMonomorphismRestriction" in your .ghci file. > > > sortBy (compare `on` fst) [(2,3),(0,1),(1,5)] ? -- test a little sort > > expression > > [(0,1),(1,5),(2,3)] > > > 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)] > > [(0,1),(1,5),(2,3)] > > > let sortpairs = sortBy (compare `on` fst) ? ?-- points-free style > > sortpairs [(2,3),(0,1),(1,5)] > > :1:24: > ?? ?No instance for (Num ()) > ?? ? ?arising from the literal `1' at :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?!