
21 Oct
2021
21 Oct
'21
6:40 p.m.
Hi cafe, today while explaining lambda functions I came across this case which I don't really understand. This is what I get using ghci λ> :t (\a b -> a + b) (\a b -> a + b) :: Num a => a -> a -> a but when loading a .hs file with just this function (without signature) add = \a b -> a + b I get λ> :t add add :: Integer -> Integer -> Integer but I can explicitly define add to have this type: add :: Num a => a -> a -> a add = \a b -> a + b Also ghc infers this polymorphic type for example for add0 a = \b -> a + b Why is the type of add without a signature inferred to Integer and not Num a? Best regards Matthias