Strange Type Error

Hello, Could anyone help me understand what is wrong with the definition of f2 in the code below? class C a b where convert :: a -> b convertToInt :: (C a Int) => a -> Int convertToInt x = convert x f1 x = convertToInt x f2 = \x -> convertToInt x f3 :: (C a Int) => a -> Int f3 = \x -> convertToInt x Thank you Regards J-C

The problem is the monomorphism restriction: http://www.haskell.org/haskellwiki/Monomorphism_restriction http://www.haskell.org/ghc/docs/7.0.2/html/users_guide/monomorphism.html http://stackoverflow.com/questions/tagged/monomorphism-restriction http://www.cs.auckland.ac.nz/references/haskell/haskell-intro-html/pitfalls.... This kicks everyone in the butt at least once. It would be good if GHC could point it out, as mine (6.12.3) just complains about no instance. Maybe GHC7 does point it out. It's a waste of people's time otherwise.

On Thu, May 26, 2011 at 06:10, Christopher Done
This kicks everyone in the butt at least once. It would be good if GHC could point it out, as mine (6.12.3) just complains about no instance. Maybe GHC7 does point it out. It's a waste of people's time otherwise.
I think the Haskell standards committee is moving in the direction of eliminating it as being the wrong solution to the problem.

OK thanks everybody !
On Thu, May 26, 2011 at 12:14 PM, Brandon Allbery
On Thu, May 26, 2011 at 06:10, Christopher Done
wrote: This kicks everyone in the butt at least once. It would be good if GHC could point it out, as mine (6.12.3) just complains about no instance. Maybe GHC7 does point it out. It's a waste of people's time otherwise.
I think the Haskell standards committee is moving in the direction of eliminating it as being the wrong solution to the problem.

On Thu, May 26, 2011 at 06:01, jean-christophe mincke
f1 x = convertToInt x f2 = \x -> convertToInt x
Absent useful things like error messages, I'll assume that you tripped over the monomorphism restriction. That is, when you have a name that doesn't take a direct parameter, there are additional constraints on that name's type. (The inner lambda is not considered for this purpose, so while in theory f1 and f2 should be identical, in practice they are not unless you use {-# LANGUAGE NoMonomorphismRestriction #-}.
participants (3)
-
Brandon Allbery
-
Christopher Done
-
jean-christophe mincke