我正在使用Text.XML.Light编写一个XML(de)序列化程序并在你的Boilerplate(在http://github.com/finnsson/Text.XML.Generic处)进行编译,到目前为止,我已经获得了“正常”ADT的代码,但我仍然坚持反序列化existentials。
我得到了存在数据类型
data DataBox where
DataBox :: (Show d, Eq d, Data d) => d -> DataBox
我正试图让它编译
instance Data DataBox where
gfoldl k z (DataBox d) = z DataBox `k` d
gunfold k z c = k (z DataBox) -- not OK
toConstr (DataBox d) = toConstr d
dataTypeOf (DataBox d) = dataTypeOf d
但我无法弄清楚如何为gunfold
实施DataBox
。
错误消息是
Text/XML/Generic.hs:274:23:
Ambiguous type variable `b' in the constraints:
`Eq b'
arising from a use of `DataBox' at Text/XML/Generic.hs:274:23-29
`Show b'
arising from a use of `DataBox' at Text/XML/Generic.hs:274:23-29
`Data b' arising from a use of `k' at Text/XML/Generic.hs:274:18-30
Probable fix: add a type signature that fixes these type variable(s)
抱怨无法找出b
的数据类型。
我也在尝试实施dataCast1
和dataCast2
但我认为没有它们就可以生活(即不正确的实施)。
我想我的问题是:
答案 0 :(得分:6)
是否可以将GADT与Scrap the Boilerplate结合使用?
我想你需要问一下haskell-cafe @。这可能是一个研究问题。