【发布时间】:2014-08-05 00:43:43
【问题描述】:
此数据类型可以有type role HCons' representational representational,它允许使用coerce 添加或删除应用于元素的新类型,而无需遍历列表。
data HNil' = HNil'
data HCons' a b = HCons' a b
但是,这些列表的语法不如以下 GADT 的语法好
data HList (l::[*]) where
HNil :: HList '[]
HCons :: e -> HList l -> HList (e ': l)
我有一个convert between these two representations 的课程,例如Prime (HList [a,b]) ~ HCons' a (HCons' b HNil')。那个班会做吗
coerceHList :: Coercible (Prime a) (Prime b) => HList a -> HList b
coerceHList = unsafeCoerce
安全吗?
【问题讨论】:
-
FWIW,是的,我想是的。但我对角色的内部知识知之甚少,无法真正提出令人信服的论点。您的示例似乎是当前角色系统不够表达的另一种情况。