[Haskell-cafe] Re: GADTs and Scrap your Boilerplate

John Creighton johns243a at gmail.com
Sat May 15 16:39:46 EDT 2010



On May 15, 2:19 pm, Oscar Finnsson <oscar.finns... at gmail.com> wrote:
> 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.html

> 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... at 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 at googlegroups.com.
> To unsubscribe from this group, send email to haskell-cafe+unsubscribe at googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/haskell-cafe?hl=en.


More information about the Haskell-Cafe mailing list