I am trying to define a new data type containing a data type with multiple parameters (phantom types) in Haskell:
newtype Dd x y z = ToDd Cudd.Cudd.DdNode deriving (Eq,Show)
data KnowStruct a b c =
KnS Cudd.Cudd.DdManager [Prp] (Dd a b c) [(Agent,[Prp])]
deriving (Eq,Show)
But this gives me the error message:
• Expected kind ‘k0 -> k1 -> *’, but ‘Dd a’ has kind ‘*’
• In the type ‘(Dd a b c)’
Why is this the case?
Is it also possible to define KnowStruct without using any requirement of context / parameter specification for the contained Dd type? e.g. :
data KnowStruct =
KnS Cudd.Cudd.DdManager [Prp] (Dd a b c) [(Agent,[Prp])]
deriving (Eq,Show)
I made a function class dealing with all variations of Dds, and only use these in the functions acting on KnowStructs - so in theory there is no need to specify what kind of Dd the KnowStruct contains..
The first one works for me, try giving them explicit kind signatures
This is possible, and is called existential quantification because the type variables don't appear in the return type.
Deriving
Show
requires standalone deriving because of the existential quantification andEq
can't be easily derived. Sincea
,b
,c
are existentially quantified when you are comparing twoKnowStruct
s you are comparingDd a1 b1 c1
andDd a2 b2 c2
with completely different type variables.I prefer the (equivalent) GADT syntax