1

When I load below haskell code file by ':l' command in GHCi.

add1 x y = x + y
add2 = \x -> \y -> x + y

Type of add1 and add2 is like below.

add1 :: Num a => a -> a -> a
add2 :: Integer -> Integer -> Integer

Why do they have different type???

UPDATE

When I input below codes in GHCi, they have same type 'Num a => a -> a -> a'.

let add1 x y = x + y
let add2 = \x -> \y -> x + y
Curry
  • 885
  • 5
  • 15
  • They have the same type on GHCi 7.8.4 and 7.10. – András Kovács Feb 15 '15 at 07:31
  • 5
    https://wiki.haskell.org/Monomorphism_restriction + defaulting rules – Philip JF Feb 15 '15 at 07:41
  • 2
    Isn't there a canonical monomorphism restriction question/answer? This question gets asked *all the time*. – Bakuriu Feb 15 '15 at 07:42
  • @AndrásKovács When I define function using let in GHCi, they have same type. But when I load source code file using ":l" command, they have different type. I test it on GHC 7.8.3. – Curry Feb 15 '15 at 07:58
  • @Philip JF I will check monomorphism restriction as your comment. Thanks. – Curry Feb 15 '15 at 08:05
  • 2
    @Bakuriu: Probably, but [none that's](http://stackoverflow.com/search?tab=votes&q=monomorphism) easy to find if you don't know the term "monomorphism". – Zeta Feb 15 '15 at 08:20
  • @Zeta Your comment is correct. I can't find answer because I don't know that term. – Curry Feb 15 '15 at 23:32

0 Answers0