views:

120

answers:

1

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 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?
+5  A: 

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.

Don Stewart
+1: http://www.mail-archive.com/[email protected]/msg75780.html
Charles Stewart
Thanks for the tip. My current bet is that José Pedro Magalhães was right, i.e. the answer to (1) is "no".
finnsson