wiki:MonomorphismRestriction/Remove

Version 1 (modified by simonmar@…, 6 years ago) (diff)

text moved from MonomorphismRestriction

Lift the monomorphism restriction =

We could simply remove the M-R from the language, but suggest that implementations issue a warning when a loss of sharing might occur due to overloading of a variable or pattern binding.

The warning would not be mandatory - the report doesn't mandate implementation behaviour of this kind, rather it would be a recommendation. To make the warning mandatory would require talking about operational semantics, which the report also doesn't do.

For:

  • Simple, removes a wart from the language
  • "As much polymorphism as possible" is in the spirit of Haskell - it is strange to limit polymorphism for performance reasons (indeed, this is arguably a poor compromise)
  • It turns out to be quite hard to demonstrate a performance problem due to the M-R, at least with GHC, because its optimiser often recovers the sharing.
  • Even if you do get loss of sharing, profiling will quickly pinpoint it
  • nhc98 has never implemented the M-R, and users haven't found any significant problems as a result
  • Hugs has a different (non-Haskell98) implementation of the M-R
  • Haskell doesn't specify an evaluation strategy so introducing the concept of 'sharing' is strange indeed.

Against:

  • Might be hard to give an accurate warning; just warning about overloaded variable bindings isn't good enough, because they don't all result in loss of sharing.
  • The warning might be confusing to new users (but if we could make it accurate, it wouldn't happen much)
  • For cases where you want the polymorphic type and don't want to write a type signature, then having the compiler emit a warning by default is undesirable.