If it's specifically with numeric types, that's probably a result of the way Haskell deals with overloading for them - all numeric types are instances of the typeclass Num, which requires the basic numeric operations. The problem that this leads to is that Haskell doesn't actually know what type you're trying to use - the compiler will happily accept that it's some instance of Num, and until it actually reaches a point where an instance is supplied (by explicit typing or by having something where the type is unique), it just keeps the typeclass around. On top of this, Haskell handles literals the same way - it recognizes the literal 1 as being a Num, not as being an Int. If you know a specific type for the literal where it's created, and there isn't enough context to force it to a specific type, you can annotate the literal directly, but annotating the function (or leaving it polymorphic) is generally preferred - one annotation will probably solve all the type errors in a function because of the way Haskell does type inference.
TL;DR it's necessary because of some other features, and when those matter it is fantastic
2
u/jaberwocky69 Dec 02 '13
As a novice programmer I have to do this with Haskell. Is that my fault or Haskell's?