我正在使用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
但我认为没有它们我也能活下去(即,不正确的实现)。
我想我的问题是:
-
有没有可能把存在主义和废弃样板结合起来?
-
如果是:如何为存在数据类型实现Gunfold?