[Haskell-beginners] Why is type "Integer -> Integer" and not "(Num a) => a -> a"?

Chaddaï Fouché chaddai.fouche at gmail.com
Thu Nov 12 12:44:59 EST 2009


On Thu, Nov 12, 2009 at 5:40 PM, Nathan M. Holden
<nathanmholden at gmail.com> wrote:
> 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.

That is not the problem : as the rest of your message acknowledge 2 is
not an Int, it is of type (Num a) => a. The issue rest squarely with
the fact that the binding f1 don't have parameter expressed on the
left side of the "=", thus the monomorphism restriction kicks in (as
alluded, probably, by your first paragraph) and GHC has to use the
defaulting rules to find a monomorphic type for f1.

-- 
Jedaï


More information about the Beginners mailing list