[GHC] #16123: QuantifiedConstraints fails to deduce trivial constraint

GHC ghc-devs at haskell.org
Thu Jan 3 19:09:01 UTC 2019


#16123: QuantifiedConstraints fails to deduce trivial constraint
-------------------------------------+-------------------------------------
        Reporter:  eschnett          |                Owner:  (none)
            Type:  bug               |               Status:  closed
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.6.3
      Resolution:  duplicate         |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #14680            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by RyanGlScott):

 * status:  new => closed
 * resolution:   => duplicate
 * related:   => #14680


Comment:

 I'm afraid what you are trying to write just won't work (at least, not
 today). This quantified constraint:

 {{{#!hs
 forall a. Ok (Dom f) a => Ok (Cod f) (f a)
 }}}

 Uses a type family in the head of the constraint, which GHC doesn't
 support. (See [https://ghc.haskell.org/trac/ghc/ticket/14860 this Trac
 ticket].) The fact that GHC 8.6 somehow accepts this as a superclass
 constraint for `Functor` is a bug, and as you've discovered, GHC won't
 actually use that constraint in any instances. On GHC HEAD, your
 (unmodified) code is rejected with an error message:

 {{{
 $ ~/Software/ghc/inplace/bin/ghc-stage2 Bug.hs
 [1 of 1] Compiling CatQC            ( Bug.hs, Bug.o )

 Bug.hs:32:1: error:
     • Quantified predicate must have a class or type variable head:
         forall (a :: ObjKind). Ok (Dom f) a => Ok (Cod f) (f a)
     • In the quantified constraint ‘forall (a :: ObjKind).
                                     Ok (Dom f) a =>
                                     Ok (Cod f) (f a)’
       In the context: (Category (Dom f), Category (Cod f),
                        forall (a :: ObjKind). Ok (Dom f) a => Ok (Cod f)
 (f a))
       While checking the super-classes of class ‘Functor’
       In the class declaration for ‘Functor’
    |
 32 | class ( Category (Dom f), Category (Cod f)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
 }}}

 There is a workaround (described in
 https://ghc.haskell.org/trac/ghc/ticket/14860#comment:19) that can
 sometimes be used. Unfortunately, this workaround doesn't work here,
 because you're trying to use a quantified constraint in a superclass
 position. #14860 is tracking this infelicity already, so I'll close this
 ticket in favor of that one.

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


More information about the ghc-tickets mailing list