为什么Haskell的“通用”类类型族“ Rep a”被标注为类型构造函数而不是类型?

时间:2020-10-06 21:16:12

标签: 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

我很好奇为什么没有这样写:

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

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

1 个答案:

答案 0 :(得分:5)

这样做是为了允许GenericGeneric1类共享它们的大多数表示类型。这是否真的是一个好主意尚有争议。尽您所能来忽略额外的参数。