
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)] <interactive>:1:24: 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?!

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)]
<interactive>:1:24: 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?!

I've been on this list for something like 7 months and I think "monomorphism restriction" is the answer to about 70% of newbie/intermediate questions. I don't always understand their questions but one can pretty much guess the answer. Daniel Fischer wrote:
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.(?)

Am Samstag 21 November 2009 00:10:48 schrieb Michael Mossey:
I've been on this list for something like 7 months and I think "monomorphism restriction" is the answer to about 70% of
Certainly seems like that sometimes. But actually it's only 46.35% ;) Earnestly, it's apparently the thing by far the most people trip over. It would probably be a good thing to have it disabled by default in ghci as that's where it bites most often. On the other hand, it means lots of easy answers on the lists 8-)
newbie/intermediate questions. I don't always understand their questions but one can pretty much guess the answer.
Daniel Fischer wrote:
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.(?)
participants (3)
-
Daniel Fischer
-
I. J. Kennedy
-
Michael Mossey