MonoLocalBinds sometimes monomorphises *global* binds
Here is a fairly simple program:
{-# LANGUAGE MonoLocalBinds #-}
module Bug where
x = 5
f y = (x, y)
Important: the monomorphism restriction is in effect.
GHC embarrassingly infers the type Any -> (Integer, Any) for f. This is because f's right-hand side mentions x, whose type is not yet known. (The monomorphism restriction means it's type is not Num a => a.) So, GHC chooses the NoGen plan for generalization. With nothing to say what the type of y should be, GHC picks Any. Bad GHC, bad. Giving x a type signature or disabling the monomorphism restriction fixes the problem.
I think the solution is simply never to do NoGen for top-level bindings.