【发布时间】:2010-05-15 10:16:06
【问题描述】:
我正在使用 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
但我不知道如何为DataBox 实现gunfold。
错误信息是
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,但我认为没有它们我也能活下去(即不正确的实现)。
我想我的问题是:
- 是否可以将存在主义与 Scrap your Boilerplate 结合起来?
- 如果是这样:如何为存在数据类型实现 gunfold?
【问题讨论】:
标签: generics reflection haskell