Skip to content

MonoLocalBinds + MonomorphismRestriction prevents generalization for a top level definition

Consider the following code sample

{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE MonomorphismRestriction #-}
tmp = 10
picker x y = if tmp > 11 then x else y
main = do
  print (picker "x" "y")
  print (picker 10 11)

It fails with the misleading error message "* No instance for (Num [Char]) arising from the literal `10'...", from what seems to be an interaction between MonoLocalBinds and MonomorphismRestriction (turn either off and the error goes away).

Should this be happening only for local bindings, or is it correct for this error to occur for top-level definitions too?

In either case, would it be possible to give a better error message here?

Trac metadata
Trac field Value
Version 8.6.2
Type Bug
TypeOfFailure OtherFailure
Priority low
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information