[Haskell-cafe] Type inference for lambda function
Matthias Güdemann
matthias.gudemann at gmail.com
Thu Oct 21 18:40:45 UTC 2021
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
More information about the Haskell-Cafe
mailing list