
On May 15, 2:19 pm, Oscar Finnsson
Hi,
I'm writing a XML (de)serializer using Text.XML.Light and Scrap your Boilerplate (a thttp://github.com/finnsson/Text.XML.Generic) and so far I got working code for "normal" ADTs but I'm stuck at deserializing GADTs.
I got the GADT
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. Not sure if this would work but you could try something like
forall d. gunfold k z c = k (z (DataBox::d->DataBox d)) -- not OK but what isn't working for you is the compiler needs to know what type of Databox to construct. Also why isn't the paramater c used? Anyway I'll look up what these functions are suppose to do and maybe I can offer further help. As for type casting you might want to look up Typeable: http://www.haskell.org/ghc/docs/6.12.1/html/libraries/base/Data-Typeable.htm...
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 GADTs with Scrap your Boilerplate? 2. If so: how do you implement gunfold for a GADT?
-- Oscar _______________________________________________ Haskell-Cafe mailing list Haskell-C...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe
-- You received this message because you are subscribed to the Google Groups "Haskell-cafe" group. To post to this group, send email to haskell-cafe@googlegroups.com. To unsubscribe from this group, send email to haskell-cafe+unsubscribe@googlegroups.com. For more options, visit this group athttp://groups.google.com/group/haskell-cafe?hl=en.