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

Shawn Willden shawn-haskell at willden.org
Thu Nov 12 04:06:00 EST 2009


On Thursday 12 November 2009 01:45:08 am Joe Fredette wrote:
> My guess is that, defining in GHCi
>
>  > let f x = x * 2
>  > let g = \x -> x * 2
>
> the former doesn't default to anything (it just does inference) since
> it's a function definition, and the latter defaults the '2' to an
> Integer because it's a value -- or some suitable analog of that
> situation.

Hmm.  Would that also explain this?

Prelude> let f1 x = x * 2
Prelude> :type f1
f1 :: (Num a) => a -> a
Prelude> let f2 = \x -> f1 x
Prelude> :type f2
f2 :: Integer -> Integer

	Shawn.


More information about the Beginners mailing list