[GHC] #9110: MonomorphismRestriction too eager

#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

#9110: MonomorphismRestriction too eager -------------------------------------+------------------------------------ Reporter: goldfire | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by dmwit): * cc: daniel@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9110#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9110: MonomorphismRestriction too eager -------------------------------------+------------------------------------ Reporter: goldfire | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): Here is what is happening: * `baz` gets the type `forall b. b -> alpha`, where `alpha` is a unification variable, plus a `Num alpha` constraint. The MR prevents us generalising the `alpha`. * Because `baz` is bitten by the MR, it is not considered "closed"; see [http://www.haskell.org/ghc/docs/7.8.2/html/users_guide/other-type- extensions.html#monomorphism 7.13.9.3 in the user manual]. Actually the user manual is badly framed here. It should say "A binding is considered closed if (a) all its free variables are imported or closed, and (b) it is unaffected by the monomorphism restriction." * Because `baz` is not closed, and `bar` mentions `baz`, `bar` is not closed. Since `LocalMonoBinds` is force, `bar` is not generalised. * Since `bar` is not genrealised, `foo` really is not as polymorphic as its type signature claims. I'll fix the user manual, but otherwise things are working fine Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9110#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9110: MonomorphismRestriction too eager -------------------------------------+------------------------------------ Reporter: goldfire | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by goldfire): Ah. I was thinking that the `MonoLocalBinds` was affecting the of the `where`-bound `_` and that somehow that was causing the problem, hence my deep confusion in that area. Your explanation makes good sense. Thanks. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9110#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9110: MonomorphismRestriction too eager
-------------------------------------+------------------------------------
Reporter: goldfire | Owner:
Type: bug | Status: closed
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.2
Resolution: fixed | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Changes (by simonpj):
* status: new => closed
* resolution: => fixed
Comment:
User manual improvement:
{{{
commit 3a61e6de311ad235aec9f0a55201656805e3c04e
Author: Simon Peyton Jones
participants (1)
-
GHC