Why are polymorphic values not inferred in Haskell?
问题 Numeric literals have a polymorphic type: *Main> :t 3 3 :: (Num t) => t But if I bind a variable to such a literal, the polymorphism is lost: x = 3 ... *Main> :t x x :: Integer If I define a function, on the other hand, it is of course polymorphic: f x = 3 ... *Main> :t f f :: (Num t1) => t -> t1 I could provide a type signature to ensure the x remains polymorphic: x :: Num a => a x = 3 ... *Main> :t x x :: (Num a) => a But why is this necessary? Why isn\'t the polymorphic type inferred? 回答1: