2

I am encountering this error when I try to derive an instance.

Cannot derive well-kinded instance of form ‘HFunctor (ControlFlowCMD ...)’
    Class ‘HFunctor’ expects an argument of kind ‘(* -> *, *)
                                                  -> * -> *’
• In the newtype declaration for ‘ControlFlowCMD’

I am trying to do this:

newtype ControlFlowCMD fs a = ControlFlowCMD (ControlCMD fs a)
  deriving HFunctor via (ControlCMD fs a)

You can see the data type and instance I am basing my type on and trying to derive here, on line 278. I am not that used to using deriving via - could anyone explain what this error means and how I would fix it?

Iceland_jack
  • 6,848
  • 7
  • 37
  • 46
Robert
  • 165
  • 10
  • @chi Sorry, I should have mentioned that I have tried that. The error message does not change. – Robert Jan 28 '21 at 09:41
  • @Robert Do you have `DataKinds` and/or `PolyKinds` enabled? That `(* -> *, *)` seems like a kind-level tuple and might require them. – danidiaz Jan 28 '21 at 09:55
  • 2
    @danidiaz Enabling either change nothing, but enabling both made it pass. Thanks! I am used to GHC screaming at me which extensions I need, but now it couldn't figure out that these were the extensions I need. – Robert Jan 28 '21 at 10:27
  • @Robert I had a similar problem here https://stackoverflow.com/a/45659560/1364288 and yes, it's a pity that GHC doesn't warn you on this. – danidiaz Jan 28 '21 at 10:36

1 Answers1

2

The problem was that (* -> *, *) or, equivalently, (Type -> Type, Type) is a kind-level tuple, and one must enable the DataKinds and PolyKinds extensions in order to handle it. (I'm not completely sure why PolyKinds is needed though; maybe it's to allow more general kind inference.)

With datatypes having complex kinds, it's often a good idea to enable StandaloneKindSignatures and give the kind signature explicitly:

import Data.Kind
type ControlFlowCMD :: (Type -> Type, Type) -> Type -> Type
newtype ControlFlowCMD fs a = ...
danidiaz
  • 26,936
  • 4
  • 45
  • 95