在Scrap Your Boilerplate 包中Data.Generics.Aliases
,有一些函数允许对一元和二元类型构造函数进行类型扩展。ext1
特别是和有定义ext2
。
现在,ext1
和是根据, 和ext2
定义的,它们是类型类的一部分,通常由机器定义。但是,没有,所以我看不到一个简单的方法来定义。dataCast1
dataCast2
Data
DeriveDataTypeable
dataCast3
ext3
是否可以定义ext3
,如果可以,如何定义?
在Scrap Your Boilerplate 包中Data.Generics.Aliases
,有一些函数允许对一元和二元类型构造函数进行类型扩展。ext1
特别是和有定义ext2
。
现在,ext1
和是根据, 和ext2
定义的,它们是类型类的一部分,通常由机器定义。但是,没有,所以我看不到一个简单的方法来定义。dataCast1
dataCast2
Data
DeriveDataTypeable
dataCast3
ext3
是否可以定义ext3
,如果可以,如何定义?
我很确定这还不够。但感觉离得很近。
ext3 :: (Data a, Typeable3 t)
=> c a
-> (forall d1 d2 d3. c (t d1 d2 d3))
-> c a
ext3 def ext = maybe def (id) (gcast3' ext)
gcast3' :: (Typeable3 t, Data a) => c (t f g h) -> Maybe (c a)
gcast3' x = r
where
r = if typeOf3 (getArg x) == typeOf3' (getArg (fromJust r))
then Just $ unsafeCoerce x
else Nothing
getArg :: c x -> x
getArg = undefined
typeOf3' z = mkTyConApp (typeRepTyCon (typeOf z)) []