[GHC] #15639: Surprising failure combining QuantifiedConstraints with Coercible

GHC ghc-devs at haskell.org
Wed Dec 5 23:25:34 UTC 2018


#15639: Surprising failure combining QuantifiedConstraints with Coercible
-------------------------------------+-------------------------------------
        Reporter:  dfeuer            |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler (Type    |              Version:  8.5
  checker)                           |             Keywords:
      Resolution:                    |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  GHC rejects       |  Unknown/Multiple
  valid program                      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by dfeuer):

 Let's go through this
 [http://downloads.haskell.org/~ghc/8.6.2/docs/html/users_guide/glasgow_exts.html
 #instance-lookup according to the user's guide]:

 > In the light of the overlap decision, instance lookup works like this
 when trying to solve a class constraint `C t`
 >
 > 1. First see if there is a given un-quantified constraint `C t`. If so,
 use it to solve the constraint.
 > 2. If not, look at all the available given quantified constraints; if
 exactly one one matches `C t`, choose it; if more than one matches, report
 an error.
 > 3. If no quantified constraints match, look up in the global instances,
 as described in ...

 When type checking the use of the `Coercion` constructor in `yeah`, we
 want `Coercible [Yeah a] [Yeah b]`. There are no given constraints
 (quantified or otherwise) matching that, so we use the global instance
 `Coercible x y => Coercible [x] [y]`, producing the wanted `Coercible
 (Yeah a) (Yeah b)`. We have no matching unquantified givens, so we look
 for quantified givens. We (should) have a match: `forall a b. Coercible
 (Yeah a) (Yeah b)`, which should solve the wanted. However, it ''appears''
 that GHC is instead choosing the global instance `forall a b. Coercible a
 b => Coercible (Yeah a) (Yeah b)`, leading to an unsatisfiable `Coercible
 a b`.

 So I don't ''think'' the current behavior matches the user's guide.

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


More information about the ghc-tickets mailing list