[Haskell-beginners] Why is type "Integer -> Integer" and not
"(Num a) => a -> a"?
Nathan M. Holden
nathanmholden at gmail.com
Thu Nov 12 11:40:35 EST 2009
This is just a theory, but in my (limited) experience, GHCi is willing to
guess at the type of values, where at functions (explicitly or implicitly
typed) it can't guess.
In your original function, it multiplied a number (Num a) => a by an Int,
therefor it must be Int -> Int (because you can't multiply a Double by an Int,
don't be crazy.
In the new function, though, it can infer the type of the 2, and therefor it
can infer it to whatever numerical type you send it.
I've run into this problem a few times, but for whatever reason I can't get
myself to fall into any of the usual ways I walk blindly into these sorts of
problems this time.
More information about the Beginners