为什么 Haskell 的“通用”类类型系列“Rep a”被注释为类型构造函数,而不是类型?

sha*_*yan 8 haskell

考虑 Haskell 的Generic课程:

class Generic a where
  -- | Generic representation type
  type Rep a :: * -> *
  -- | Convert from the datatype to its representation
  from  :: a -> (Rep a) x
  -- | Convert from the representation to the datatype
  to    :: (Rep a) x -> a
Run Code Online (Sandbox Code Playgroud)

我很好奇为什么它没有写成如下:

class Generic a where
  -- | Generic representation type
  type Rep a :: *
  -- | Convert from the datatype to its representation
  from  :: a -> Rep a
  -- | Convert from the representation to the datatype
  to    :: Rep a -> a
Run Code Online (Sandbox Code Playgroud)

更具体地说,类型变量x在标准定义中代表什么?

dfe*_*uer 5

这样做是为了允许GenericGeneric1类共享它们的大部分表示类型。这是否真的是一个好主意值得商榷。尽量忽略额外的参数。