This tiny Haskell program reads two space-separated numbers from console and prints their sum:
main = do
line <- getLine
let n1:n2:_ = map read $ words line
print $ n1 + n2
I'd expect the compilation to fail because of ambiguity: +
restricts the type of n1
and n2
to Num
typeclass and not to a specific type. However GHC 7.10 successfully compiles it inferring Integer
type (replacing +
by /
changes the inferred type to Double
). What is the explanation for that?