2

I wrote what I think is the same function in the following three ways:

addThree x y z = x + y + z
addThree' = \x y z -> x + y + z
addThree'' = \x -> \y -> \z -> x + y + z 

Yet when I load and check their types in GHCi using :t, it gives me a very weird answer:

addThree :: Num a => a -> a -> a -> a
addThree' :: Integer -> Integer -> Integer -> Integer
addThree'' :: Integer -> Integer -> Integer -> Integer

Why do the lambdas have different, specialized types while the normal one has the correct type?

badcook
  • 3,699
  • 14
  • 25
Luster
  • 171
  • 1
  • 1
  • 5
  • 8
    Good intuition that these should be the same. This is a special case called the monomorphism restriction which you can read about by googling – luqui Nov 06 '16 at 03:24
  • Presumably you are using a version of ghci before 7.8.1? – mnoronha Nov 06 '16 at 03:28
  • @luqui: There's a [very exhaustive answer by Bakuriu](http://stackoverflow.com/q/32496864/1139697), so feel free to close questions like this as duplicate of theirs. – Zeta Nov 06 '16 at 09:53

0 Answers0