No monomorphism restriction
- In a source file
- In GHCi
NoMonomorphismRestriction extension and its sibling,
MonomorphismRestriction, All extensions come in pairs like this, one that turns a thing on and the other that turns the same thing off again. It is not usually useful to discuss both, since most are not enabled by default and so you rarely have a need to turn it off using the
-XNo... extension. The two extensions for turning on and off the monomorphism restriction, however, are an exception because the default settings for compiled code and interactive code in GHCi are different. enable you to control a specific quirk of the type inference system: the monomorphism restriction.
A flag to disable monomorphism restriction has existed since GHC 5.00. The
NoMonomorphismRestriction extension GHC documentation for
NoMonomorphismRestriction in its present form has existed since the introduction of the
LANGUAGE pragma in GHC 6.6.
Since GHC 7.8.1, this extension has been on by default in GHCi for interactive code, while it remains off by default for compiled or interpreted code. This means that, in times when the monomorphism restriction is applicable, you should expect different default behavior between compiled code and code entered at the interactive prompt in GHCi. This lesson gives examples of both defaults and how to avoid worrying about the monomorphism restriction.