Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Haskell, why does binding a value to a variable name no longer force the system to commit to a type?

: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?

like image 912
Peter Drake Avatar asked Dec 06 '25 17:12

Peter Drake


1 Answers

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

like image 69
Carl Avatar answered Dec 08 '25 17:12

Carl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!