gpt4 book ai didi

generics - 存在主义和废弃你的样板

转载 作者:行者123 更新时间:2023-12-03 22:21:57 24 4
gpt4 key购买 nike

我正在使用 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 的数据类型.

我也在尝试实现 dataCast1dataCast2但我想我可以没有它们(即不正确的实现)。

我想我的问题是:
  • 是否可以将存在主义与 Scrap your Boilerplate 结合起来?
  • 如果是这样:您如何为存在数据类型实现 gunfold?
  • 最佳答案

    Is it possible to combine GADTs with Scrap your Boilerplate?



    我想你需要问 haskell-cafe@。这可能是一个研究问题。

    关于generics - 存在主义和废弃你的样板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2839713/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com