Can't resolve superclass from MPTC
Summary
If I have a Functor
constraint, I'm told it's redundant. If I remove it, I get a (rather poor) error message. This is reduced from production code.
Steps to reproduce
{-# language MultiParamTypeClasses #-}
{-# language UndecidableInstances #-}
{-# options_ghc -Wredundant-constraints #-}
module Super where
newtype KeyAttributes = KeyAttributes { keySort :: Int }
class Functor base => Synthetic syn base where
synthetic :: base syn -> syn
instance (Synthetic Int base, {- Functor base -}) => Synthetic KeyAttributes base where
synthetic base = KeyAttributes { keySort = synthetic (keySort <$> base) }
With Functor base
commented out, I get
Super.hs:7:10: error:
• Could not deduce (Functor base)
arising from the superclasses of an instance declaration
from the context: Synthetic Int base
bound by the instance declaration at Super.hs:7:10-59
Possible fix:
add (Functor base) to the context of the instance declaration
• In the instance declaration for ‘Synthetic KeyAttributes base’
|
7 | instance Synthetic Int base => Synthetic KeyAttributes base where
If I uncomment that, I get
Super.hs:7:10: warning: [-Wredundant-constraints]
• Redundant constraint: Functor base
• In the instance declaration for ‘Synthetic KeyAttributes base’
|
7 | instance (Synthetic Int base, Functor base) => Synthetic KeyAttributes base where
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expected behavior
If reasonably implementable, I'd like the code to compile with no warnings without a Functor
constraint. Otherwise, I don't want a warning with it, and I want a better explanation for why it can't be inferred without.
Environment
- GHC version used: 9.4.4
Optional:
- Operating System:
- System Architecture: