Others have addressed many aspects of this question quite well. I'd like to say a word about the rationale behind why +
has the type signature Num a => a -> a -> a
.
Firstly, the Num
typeclass has no way to convert one artbitrary instance of Num
into another. Suppose I have a data type for imaginary numbers; they are still numbers, but you really can't properly convert them into just an Int
.
Secondly, which type signature would you prefer?
(+) :: (Num a, Num b) => a -> b -> a
(+) :: (Num a, Num b) => a -> b -> b
(+) :: (Num a, Num b, Num c) => a -> b -> c
After considering the other options, you realize that a -> a -> a
is the simplest choice. Polymorphic results (as in the third suggestion above) are cool, but can sometimes be too generic to be used conveniently.
Thirdly, Haskell is not Blub. Most, though arguably not all, design decisions about Haskell do not take into account the conventions and expectations of popular languages. I frequently enjoy saying that the first step to learning Haskell is to unlearn everything you think you know about programming first. I'm sure most, if not all, experienced Haskellers have been tripped up by the Num typeclass, and various other curiosities of Haskell, because most have learned a more "mainstream" language first. But be patient, you will eventually reach Haskell nirvana. :)
fromIntegral
".x.f()
vsg=x.f; g();
in Javascript. It sucks when variables break the substitution model abstraction.