Why do 3 and x (which was assigned 3) have different inferred types in Haskell? [duplicate]

There’s another factor here, mentioned in some of the links which acfoltzer includes, but it might be worth making explicit here. You’re encountering the effect of the monomorphism restriction. When you say let x = 5 you make a top-level definition of a variable. The MR insists that such definitions, when otherwise unaccompanied by a … Read more

Why are polymorphic values not inferred in Haskell?

It’s the monomorphism restriction which says that all values, which are defined without parameters and don’t have an explicit type annotation, should have a monomorphic type. This restriction can be disabled in ghc and ghci using -XNoMonomorphismRestriction. The reason for the restriction is that without this restriction long_calculation 42 would be evaluated twice, while most … Read more

What is the monomorphism restriction?

What is the monomorphism restriction? The monomorphism restriction as stated by the Haskell wiki is: a counter-intuitive rule in Haskell type inference. If you forget to provide a type signature, sometimes this rule will fill the free type variables with specific types using “type defaulting” rules. What this means is that, in some circumstances, if … Read more