fin*_*son 8 generics reflection haskell
我正在使用Text.XML.Light和Scrap你的Boilerplate编写XML(de)序列化程序(在http://github.com/finnsson/Text.XML.Generic),到目前为止,我得到了"正常"ADT的工作代码但我坚持反复化存在主义.
我得到了存在主义数据类型
data DataBox where
DataBox :: (Show d, Eq d, Data d) => d -> DataBox
Run Code Online (Sandbox Code Playgroud)
而我正在尝试将其编译
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
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何实现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)
Run Code Online (Sandbox Code Playgroud)
它抱怨无法找出数据类型b.
我也试图实现dataCast1,dataCast2但我认为我可以没有它们(即不正确的实现).
我想我的问题是:
| 归档时间: |
|
| 查看次数: |
340 次 |
| 最近记录: |