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

标签 generics reflection haskell

我正在使用 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/

    相关文章:

    ios - Swift 中的多个泛型参数

    c# - 如何在 C# 中扩展返回泛型值的泛型类?

    go - 使用反射附加到 slice

    haskell - GHC 分析器输出

    Java 泛型、链表

    c# - 如何将 List<T> 初始化为给定大小(相对于容量)?

    c# - 如何找到带有 params 参数的方法的用法,以使参数不为空?

    reflection - 如何检查 Rust 的编译时是否实现了特征?

    haskell - GHCJS-DOM 事件指导

    haskell - 如何在 Haskell 中查找运行时的核心数量