2010-05-15 27 views
8

我正在寫一個XML(德)序列化使用Text.XML.Light和廢鋼鍋(在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 

,但我無法弄清楚如何實施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) 

它抱怨不能夠搞清楚b的數據類型。

我也試圖實施dataCast1dataCast2但我認爲我可以生活在沒有他們(即不正確的實施)。

我想我的問題是:

  1. 是否有可能existentials廢鋼的樣板結合?
  2. 如果是這樣的話:你如何爲存在數據類型實施gunfold?

回答

6

是否可以合併GADT和廢料鍋板?

我想你需要問問haskell-cafe @。這可能是一個研究問題。

+0

+1:http://www.mail-archive.com/[email protected]/msg75780.html – 2010-05-18 08:42:52

+0

感謝您的提示。我目前的賭注是,何塞佩德羅馬加良斯是正確的,即(1)的答案是「否」。 – finnsson 2010-05-23 08:36:31