Because the default for integral literal numbers is Integer
, and not Int
:
4.3.4 Ambiguous Types, and Defaults for Overloaded Numeric Operations
[...]
Only one default declaration is permitted per module, and its effect is limited to that module. If no default declaration is given in a module then it assumed to be:
default (Integer, Double)
Note that you can fix this easily if you change the type of addNumLists
and add the Integer
instance:
-- We don't need `Int`, we only need `+`, so anything that is `Num` should work
addNumLists :: (Num a) => [a] -> [a] -> [a]
addNumLists (x : xs) (y : ys) = x + y : addNumLists xs ys
addNumLists _ _ = []
instance NewList Integer where
addLists = addNumLists