5

Scrap Your Boilerplate 包Data.Generics.Aliases,有一些函数允许对一元和二元类型构造函数进行类型扩展。ext1特别是和有定义ext2

现在,ext1和是根据, 和ext2定义的,它们是类型类的一部分,通常由机器定义。但是,没有,所以我看不到一个简单的方法来定义。dataCast1dataCast2DataDeriveDataTypeabledataCast3ext3

是否可以定义ext3,如果可以,如何定义?

4

1 回答 1

0

我很确定这还不够。但感觉离得很近。

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)) []
于 2013-01-25T19:53:58.263 回答