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

GHC ghc-devs at haskell.org
Thu Jan 3 18:16:13 UTC 2019


#16123: QuantifiedConstraints fails to deduce trivial constraint
-------------------------------------+-------------------------------------
           Reporter:  eschnett       |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.6.3
           Keywords:                 |  Operating System:  Unknown/Multiple
  QuantifiedConstraints              |
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 While experimenting with quantified constraints, I find I need to
 explicitly specify a quantified constraint in an instance declaration that
 I think should be deduced automatically. When I leave it out, GHC
 complains that it cannot deduce {{{Num (f a)}}} in the code below.

 The full source code is attached. The relevant lines are
 {{{
 instance ( Functor f, Dom f ~ NFun, Cod f ~ NFun
          , forall a. Ok NFun a => Num a -- I don't want to write this
 constraint
          ) => Functor (NIdF f) where
   type Dom (NIdF f) = Dom f
   type Cod (NIdF f) = Cod f
   fmap f = NFun \(NIdF xs) -> NIdF (neval (fmap f) xs)
 }}}
 where the line marked "I don't want to write ..." points to the constraint
 I don't want to have to write manually. The definition of the {{{NFun}}}
 is
 {{{
 instance Category NFun where
   type Ok NFun a = Num a
   id = NFun P.id
   NFun g . NFun f = NFun (g P.. f)
 }}}

 Note that the constraint in question does not involve the type {{{NIdF}}}
 for which the instance is declared – it is a generic condition that is
 always true, given the instance declaration of {{{NFun}}} (see the
 definition of {{{Ok}}} there).

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


More information about the ghc-tickets mailing list