[Haskell-cafe] Type inference for lambda function
Viktor Dukhovni
ietf-dane at dukhovni.org
Thu Oct 21 18:47:18 UTC 2021
On Thu, Oct 21, 2021 at 08:40:45PM +0200, Matthias Güdemann wrote:
> 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
Compare:
$ ghci -XNoMonomorphismRestriction
λ> x = \a b -> a + b
λ> :t x
x :: Num a => a -> a -> a
with
$ ghci -XMonomorphismRestriction
λ> x = \a b -> a + b
λ> :t x
x :: Integer -> Integer -> Integer
--
Viktor.
More information about the Haskell-Cafe
mailing list