[GHC] #9110: MonomorphismRestriction too eager
GHC
ghc-devs at haskell.org
Wed May 14 19:07:46 UTC 2014
#9110: MonomorphismRestriction too eager
------------------------------------+-------------------------------------
Reporter: goldfire | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.2
Keywords: | Operating System: Unknown/Multiple
Architecture: Unknown/Multiple | Type of failure: None/Unknown
Difficulty: Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: |
------------------------------------+-------------------------------------
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 type
`GHC.Exts.Any`.
* Without the MR, `bar` gets the type `forall t.t`.
* The MR bites `baz`, as it should.
According to the rules in
[http://www.haskell.org/onlinereport/decls.html#sect4.5.5 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.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9110>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list