Type inference doesn't always calculate the most generic type?

Hello, 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? Regards, Christophe Delord.

On Thu, May 28, 2015 at 10:54:38PM +0200, Christophe Delord wrote:
Hello,
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 just fired up ghci: λ> let mapabs = map abs λ> :t mapabs mapabs :: Num b => [b] -> [b] ghc 7.10.1

On Thu, May 28, 2015 at 4:54 PM, Francesco Ariis
I just fired up ghci:
λ> let mapabs = map abs λ> :t mapabs mapabs :: Num b => [b] -> [b]
ghc 7.10.1
Sufficiently recent ghc disables the monomorphism restriction inside ghci (only --- compiled code, including code compiled by ghci, as opposed to code entered at the prompt, still uses it). Try ":seti". -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

The monomorphism restriction is turned off by default in ghci since version
7.8.1, so you'll see this behavior with newer versions of GHC and the
original behavior with older ones.
On Thu, May 28, 2015 at 1:54 PM, Francesco Ariis
On Thu, May 28, 2015 at 10:54:38PM +0200, Christophe Delord wrote:
Hello,
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 just fired up ghci:
λ> let mapabs = map abs λ> :t mapabs mapabs :: Num b => [b] -> [b]
ghc 7.10.1 _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Le Thu, 28 May 2015 14:01:50 -0700,
Tikhon Jelvis
The monomorphism restriction is turned off by default in ghci since version 7.8.1, so you'll see this behavior with newer versions of GHC and the original behavior with older ones.
I'm using an old version (7.6.3) on Debian. I'll try to install a newer version. Thank you for all these answers.

On Thu, May 28, 2015 at 4:54 PM, Christophe Delord
Prelude> let mapabs = map abs
This is the monomorphism restriction. https://wiki.haskell.org/Monomorphism_restriction -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
participants (4)
-
Brandon Allbery
-
Christophe Delord
-
Francesco Ariis
-
Tikhon Jelvis