开发者

Existentials and Scrap your Boilerplate

I'm writing a XML (de)serializer using Text.XML.Light and Scrap your Boilerplate (at http://github.com/finnsson/Text.XML.Generic) and so far I got working code for "normal" ADTs but I'm stuck at deserializing existentials.

I got the existential data type

data DataBox where
  DataBox :: (Show d, Eq d, Data d) => d -> DataBox

and I'm trying to get this to compile

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

but I can't figure out how to implement gunfold for DataBox.

The error message is

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)

It's complaining about not being able to figure out the data type of b.

I'm also trying 开发者_JS百科to implement dataCast1 and dataCast2 but I think I can live without them (i.e. an incorrect implementation).

I guess my questions are:

  1. Is it possible to combine existentials with Scrap your Boilerplate?
  2. If so: how do you implement gunfold for an existential data type?


Is it possible to combine GADTs with Scrap your Boilerplate?

I think you will need to ask haskell-cafe@. This is possibly a research question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜