Hugs type labels contain additional type restrictions?

Probably playing with Haskell, and I'm at a dead end:

Hugs> :type (\x -> x^2)
\x -> x ^ 2 :: (Integral a, Num b) => b -> b

What is doing there a? How should I read this? If I type the same in GHCi, it will give me the result that I would expect:

Prelude> :type (\x -> x^2)
(\x -> x^2) :: Num a => a -> a

Is this a mistake in the arms?

+5
source share
2 answers

The restriction Integralcomes from the indicator 2. Remember that in Haskell, whole literals are actually polymorphic type values Num a => a. The compiler then indicates that since it is used as an exponent (^) :: (Num a, Integral b) => a -> b -> a, it should be of a more limited type Integral a => a.

, Haskell defaulting, . Integer. , :type Hugs , , GHCi , default.

, .

Hugs> :type (\x -> x^(2 :: Integer))
\x -> x ^ 2 :: Num a => a -> a
+7

, (^). :t (^) ghci (^) :: (Num a, Integral b) => a -> b -> a. , , ^ Integral, 2, .

+3

All Articles