Confusing type signature
I was working with some buggy numerical code of mine, and I was having problems with some types involving exponentiation. My working hypothesis was that the problem involved using (^)
with a numerical type I had defined - I had checked (^)
's type through :t and saw:
(^) :: forall a b. (Integral b, Num a) => a -> b -> a
I immediately thought that I needed another type class declaration for my new type, and went haring off on that tangent for a long time. Eventually someone on #haskell pointed out to me that the *base* could be Num, but the power to which it was being raised had to be Integral and that my problems stemmed from going foo^(1/3), and that what I needed was more along the lines of foo**(1/3).
My confusion stemmed from the variables - the forall declaration goes, in order, a-b, and the curried signature itself goes a-b as well, but the classes goes b-a! This apparently is for no particular reason, and so I think it'd be good if the signatures :t displayed could be a little more consistent and go a-b as well, so it'd be instead:
(^) :: forall a b. (Num a, Integral b) => a -> b -> a
A small thing, perhaps, but it did trip me up.