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

Dag Hovland dag.hovland at uib.no
Thu Nov 12 03:37:28 EST 2009


Hi!

I have a problem with understanding some types given by ghc and hugs.
The file loaded is:

f1 = \x -> x * 2
f2 x = x * 2

After they are loaded I get the following from ghci

*Main> :t f1
f1 :: Integer -> Integer
*Main> :t f2
f2 :: (Num a) => a -> a
*Main> :t \x -> x * 2
\x -> x * 2 :: (Num a) => a -> a


I do not understand why f1 is given Integer -> Integer as a type and not
the polymorphic (Num a) => a -> a. I believed that f1, f2 and the lambda
expression should all have the same type. Similar output to that above
is given by Hugs.

Thanks,

Dag Hovland
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3880 bytes
Desc: S/MIME Cryptographic Signature
Url : http://www.haskell.org/pipermail/beginners/attachments/20091112/a88251b0/smime.bin


More information about the Beginners mailing list