考虑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
代表什么?
答案 0 :(得分:5)
这样做是为了允许Generic
和Generic1
类共享它们的大多数表示类型。这是否真的是一个好主意尚有争议。尽您所能来忽略额外的参数。