MonomorphismRestriction too eager
This strange example came up on IRC:
{-# LANGUAGE MonoLocalBinds, MonomorphismRestriction #-}
foo :: a
foo = bar
bar = undefined where
_ = baz undefined
baz = const [1]
yields
/Users/rae/temp/Bug.hs:4:7:
Couldn't match expected type ‘a’ with actual type ‘t0’
because type variable ‘a’ would escape its scope
This (rigid, skolem) type variable is bound by
the type signature for foo :: a
at /Users/rae/temp/Bug.hs:3:8
Relevant bindings include
foo :: a (bound at /Users/rae/temp/Bug.hs:4:1)
In the expression: bar
In an equation for ‘foo’: foo = bar
Setting either NoMonoLocalBinds
or NoMonomorphismRestriction
fixes the problem. After some staring at this, I didn't get to the bottom of it. But I did learn some things:
- If we remove the definition for
foo
, the module compiles. - With the monomorphism restriction (MR),
bar
gets the typeGHC.Exts.Any
. - Without the MR,
bar
gets the typeforall t.t
. - The MR bites
baz
, as it should.
According to the rules in the Haskell Report, it seems that the MR should not bite bar
, as bar
's inferred type's unification type variable is not constrained -- this is why I'm posting the example as a bug.
But, I may be entirely mistaken, as the whole example makes my brain go a little fuzzy. In particular, I'm a little mystified how MonoLocalBinds
enters the picture, but it is necessary to tickle the problem. Apologies if GHC is behaving correctly here.
Trac metadata
Trac field | Value |
---|---|
Version | 7.8.2 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |