我正在使用 Text.XML.Light 编写一个 XML(反)序列化程序并废弃你的样板(在 http://github.com/finnsson/Text.XML.Generic ),到目前为止,我得到了“正常”ADT 的工作代码,但我一直在反序列化存在。
我得到了存在数据类型
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
但我想我可以没有它们(即不正确的实现)。我想我的问题是:
最佳答案
Is it possible to combine GADTs with Scrap your Boilerplate?
我想你需要问 haskell-cafe@。这可能是一个研究问题。
关于generics - 存在主义和废弃你的样板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2839713/