我有一个在GHC7.4.1中通过DataKinds提升的数据类型,还有一个给定的类型类,我想用它来做特定类型的操作。
data Type = TInt32 | TInt64 | TInt16
class TypeTraits a where
...然后,我尝试创建提升类型的类型类实例,如下所示:
instance TypeTraits TInt32 where
...我得到以下类型的错误:
Kind mis-match
The first argument of `TypeTraits' should have kind `*',
but `TInt32' has kind `Type'
In the instance declaration for `TypeTraits TInt32'尝试通过指定“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'发布于 2012-04-24 03:12:07
问题出在类的主体中;具有提升类型的类型没有任何值,因此您不能有一个以提升类型作为参数的函数。您必须使用Proxy a -> String或类似的工具。
顺便说一句,如果您打开了PolyKinds扩展,那么您应该能够完全省略kind注释。(实际上,您可能需要这样做,以定义您自己的Proxy类型,因为我认为来自Data.Proxy的类型可能是* -> *,而您需要Type -> *。如果在PolyKinds为on的情况下定义data Proxy p = Proxy,则会将其推断为AnyK -> *。)
https://stackoverflow.com/questions/10286680
复制相似问题