存在和废弃你的Boilerplate

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)

但我无法弄清楚如何实现gunfoldDataBox.

错误消息是

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但我认为我可以没有它们(即不正确的实现).

我想我的问题是:

  1. 是否有可能将存在与废弃的锅炉结合起来?
  2. 如果是这样的话:你如何为存在数据类型实现枪支?

Don*_*art 6

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

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