I have a data type that I promote via DataKinds in ghc 7.4.1 and a given typeclass that I want to use to do type specific operations.
data Type = TInt32 | TInt64 | TInt16
class TypeTraits a where
...
And then I try to create typeclass instances of the promoted types like so:
instance TypeTraits TInt32 where
...
I get errors of the following type:
Kind mis-match
The first argument of `TypeTraits' should have kind `*',
but `TInt32' has kind `Type'
In the instance declaration for `TypeTraits TInt32'
trying to fix this by specifying the kind of 'a':
class TypeTraits (a :: Type) where
...
Kind mis-match
Expected kind `ArgKind', but `a' has kind `Type'
In the type `a -> String'
In the class declaration for `TypeTraits'
The problem is in the body of the class; types that have a lifted kind don't have any values, so you can't have a function that takes one as a parameter. You'll have to use Proxy a -> String
or similar.
By the way, if you turn on the PolyKinds
extension then you should be able to omit the kind annotation entirely. (Actually, you might have to do this, to define your own Proxy
type, since I think the one from Data.Proxy might be * -> *
, whereas you need Type -> *
. If you define data Proxy p = Proxy
with PolyKinds
on, then it'll be inferred as AnyK -> *
.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With