【问题标题】:Existentials and Scrap your Boilerplate存在主义和废弃你的样板
【发布时间】: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的数据类型。

我也在尝试实现dataCast1dataCast2,但我认为没有它们我也能活下去(即不正确的实现)。

我想我的问题是:

  1. 是否可以将存在主义与 Scrap your Boilerplate 结合起来?
  2. 如果是这样:如何为存在数据类型实现 gunfold?

【问题讨论】:

    标签: generics reflection haskell


    【解决方案1】:

    是否可以将 GADT 与 Scrap your Boilerplate 结合起来?

    我认为您需要询问 haskell-cafe@。这可能是一个研究问题。

    【讨论】:

    • 感谢您的提示。我目前的赌注是 José Pedro Magalhães 是对的,即 (1) 的答案是“否”。
    猜你喜欢
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 2019-03-21
    相关资源
    最近更新 更多