:t 3
gives 3 :: Num a => a
, because the literal 3 doesn't have a specific type.
Back in 2013 when I made this video, if I bound 3 to a variable name with let x = 3
, Haskell would have to commit to a type, so :t x
would give x :: Integer
.
When I repeated this more recently (2022), though, I got x :: Num a => a
. Apparently a value bound to a variable can now delay committing to a type.
What changed?
CodePudding user response:
This behavior was the result of the monomorphism restriction. The restriction is still enabled by default in regular compilation, but it was disabled in ghci because without global inference it was a lot more unwieldy.
https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/monomorphism.html
Since GHC 7.8.1, the monomorphism restriction is switched off by default in GHCi’s interactive options