[Haskell-cafe] GADTs and Scrap your Boilerplate

Ben Millwood haskell at benmachine.co.uk
Sun May 16 05:49:46 EDT 2010


On Sun, May 16, 2010 at 2:34 AM, Tom Hawkins <tomahawkins at gmail.com> wrote:
>> I got the GADT
>>
>> data DataBox where
>>   DataBox :: (Show d, Eq d, Data d) => d -> DataBox
>>
> [snip]
>>
>> 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:
>
> I had a similar difficultly in Atom making a GADT a member of Eq.  At
> one point I had my head wrapped around the reason for the problem, but
> now it escapes me.  However, I remember the solution: I created a
> function to convert the GADT into another, unGADT type, which was then
> used to compute (==).
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

Have you tried using StandaloneDeriving (and DeriveDataTypeable)?

According to http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/deriving.html#stand-alone-deriving
you can't derive instances for GADTs normally but a standalone
derivation will at least attempt to make an instance as if it was an
ordinary data type.


More information about the Haskell-Cafe mailing list