scv*_*lex 5 haskell generic-programming scrap-your-boilerplate
在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)) []
Run Code Online (Sandbox Code Playgroud)