Skip to content

QuantifiedConstraints fails to deduce trivial constraint

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).

Trac metadata
Trac field Value
Version 8.6.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information