Haskell 如何创建升级类型的typeclass实例?

Haskell 如何创建升级类型的typeclass实例?,haskell,typeclass,Haskell,Typeclass,我有一个通过ghc 7.4.1中的DataTypes升级的数据类型和一个给定的typeclass,我想用它来执行特定类型的操作 data Type = TInt32 | TInt64 | TInt16 class TypeTraits a where ... 然后我尝试创建提升类型的typeclass实例,如下所示: instance TypeTraits TInt32 where ... 我收到以下类型的错误: Kind mis-match The first argument o

我有一个通过ghc 7.4.1中的DataTypes升级的数据类型和一个给定的typeclass,我想用它来执行特定类型的操作

data Type = TInt32 | TInt64 | TInt16
class TypeTraits a where
  ...
然后我尝试创建提升类型的typeclass实例,如下所示:

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'

问题出在班里;具有提升类型的类型没有任何值,因此不能使用将一个值作为参数的函数。您必须使用
a->String
或类似工具


顺便说一句,如果打开
PolyKinds
扩展,那么应该能够完全忽略kind注释。(实际上,您可能需要这样做,来定义您自己的
代理
类型,因为我认为是来自数据的类型。代理可能是
*->*
,而您需要
类型->*
。如果您使用
多种类
来定义
数据代理p=Proxy
,那么它将被推断为
AnyK->*

中的代理数据类型最终是有意义的,谢谢!您可以在
区域中输入什么内容
TInt32
不是有人居住的类型,因此它不能在值位置单独使用
a
。我猜类似于
crazyThing::TypeTraits a=>SomeTypeConstructor a
?我很难想象像这样的东西是如何有用的,尽管如果我真的伸懒腰,我可以想象它在某种程度上是有用的。也许吧。我们的想法是让每个例子都有自己的特点。因此,我不是在寻找值,而仅仅是一个占位符,用于指定typeclass,从而指定我想要在那里选择的函数。例如:
classtypetraits(a::Type),其中Type-htypeasizeof::Proxy a->Int