Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

haskell - Deriving Via: Cannot derive well-kinded instance

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?

question from:https://stackoverflow.com/questions/65934095/deriving-via-cannot-derive-well-kinded-instance

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...