This data type can have type role HCons' representational representational
, which allows using coerce
to add or remove newtypes applied to the elements, without needing to traverse the list.
data HNil' = HNil'
data HCons' a b = HCons' a b
However the syntax for those lists is not as nice as those with the following GADT
data HList (l::[*]) where
HNil :: HList '[]
HCons :: e -> HList l -> HList (e ': l)
I have a class to convert between these two representations, such that Prime (HList [a,b]) ~ HCons' a (HCons' b HNil')
. Does that class make
coerceHList :: Coercible (Prime a) (Prime b) => HList a -> HList b
coerceHList = unsafeCoerce
safe?