[GHC] #16252: QuantifiedConstraints: lack of inference really is a problem

GHC ghc-devs at haskell.org
Tue Jan 29 09:17:53 UTC 2019


#16252: QuantifiedConstraints: lack of inference really is a problem
-------------------------------------+-------------------------------------
        Reporter:  lightandlight     |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.6.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 Interesting!  I can see what is happening.

 Given a binding `g = rhs`, GHC infers all the constraints C from `rhs` and
 tries to generalise.   Currently that works as follows (`simplifyInfer`)

 1. `approximateWC`: find `quant_pred_candidates`, the subset of
 constraints in C over which we could conceivably quantify.

 2. Pick a set of `quant_pred_candidates` to quantify over

 3. Crucially, do not generalise over any type variable free in a
 constraint we decide not to generalise in Step 2.    (If we generalise
 over that type variable, the constraint will probably become insoluble.)

 The problem is that we don't account for constraints (such as implication
 constraints) that Step 1 discards!  We do generalise over their type
 variables, and they duly become insoluble. That's why your definition of
 `g` is being generalised.

 Solution: don't generalise over any type variable free in a constraint
 that we can't quantify.

 I'm quite surprised this has not come up before.  The fix will be a big
 fiddly but not really hard.

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


More information about the ghc-tickets mailing list