[Haskell-cafe] Type inference doesn't always calculate the most generic type?
haskell at cdsoft.fr
Thu May 28 20:54:38 UTC 2015
I'm new here. Sorry if this question has already been asked.
I have noticed something strange about type inference.
Prelude> :t abs
abs :: Num a => a -> a
Prelude> let mapabs = map abs
Prelude> :t mapabs
mapabs :: [Integer] -> [Integer]
Prelude> :t (map abs)
(map abs) :: Num b => [b] -> [b]
I think that "mapabs" and "map abs" should have the same generic type.
In a program I can force the type like this:
mapabs = map abs
mapabs' :: (Num a) => [a] -> [a]
mapabs' = map abs
but mapabs still have the type [Integer] -> [Integer]
Are there any reason for this?
More information about the Haskell-Cafe