In fact, there are three exponentiation operators: (^) , (^^) and (**) . ^ is a non-negative integral exponentiation, ^^ is an integer exponentiation, and ** is an exponentiation with a floating point:
(^) :: (Num a, Integral b) => a -> b -> a (^^) :: (Fractional a, Integral b) => a -> b -> a (**) :: Floating a => a -> a -> a
The reason is type safety: the results of numerical operations are usually of the same type as the input arguments. But you cannot raise Int to a floating point level and get a result of type Int . And so the type system does not allow you to do this: (1::Int) ** 0.5 creates a type error. The same goes for (1::Int) ^^ (-1) .
Another way: Num types are closed in ^ (they do not have to have a multiplicative inverse), Fractional types are closed in ^^ , Floating types are closed in ** . Since there is no Fractional instance for Int , you cannot raise it to negative power.
Ideally, the second argument ^ will be statically bounded by a non-negative (currently 1 ^ (-2) throws an exception at runtime). But there is no type for natural numbers in Prelude .
Mikhail Glushenkov Jun 19 2018-11-11T00: 00Z
source share