[GHC] #15931: MonoLocalBinds + MonomorphismRestriction prevents generalization for a top level definition

GHC ghc-devs at haskell.org
Wed Nov 21 22:46:56 UTC 2018


#15931: MonoLocalBinds + MonomorphismRestriction prevents generalization for a top
level definition
-------------------------------------+-------------------------------------
        Reporter:  theindigamer      |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  low               |            Milestone:  ⊥
       Component:  Compiler          |              Version:  8.6.2
      Resolution:                    |             Keywords:
                                     |  MonoLocalBinds,
                                     |  MonomorphismRestriction
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Incorrect         |  Unknown/Multiple
  error/warning at compile-time      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 Hmm.  Here is what is happening.

 * `tmp` is not generalise because of the monomorphism restriction.  So we
 get `tmp :: alpha`, for some as-yet-unknown type `alpha`; plus the
 constraint `Num alpha`.

 * `MonoLocalBinds` prevents generalisation of a binding if it mentions
 anything that has an open type; that is, a type with free type variables.
 `tmp` does, so `picker` is not generalised.  So it gets type `picker ::
 gamma -> gamma -> gamma`.

 * Now we apply picker to both `[Char]` (from `picker "x" "y"`) and `delta`
 (where we also need `Num delta`) from `picker 10 11`.  So we say `gamma :=
 delta := [Char]` and get stuck on `Num [Char]`.

 That's the diagnosis.  The error message is unhelpful -- but it's not
 obvious to me how to improve it.

 What error message would you like?

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15931#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list