[Haskell-cafe] Type system trickery

Andrew Coppin andrewcoppin at btinternet.com
Mon Jun 22 14:43:58 EDT 2009


Brent Yorgey wrote:
> On Sun, Jun 21, 2009 at 09:16:12PM +0100, Andrew Coppin wrote:
>   
>> Niklas Broberg wrote:
>>     
>>> That's what GADTs are for:
>>>
>>> data Flag = HasZoo | NoZoo
>>>
>>> data Foobar a where
>>>   Foo :: Foobar a -> Foobar a
>>>   Bar :: Foobar a -> Foobar a
>>>   Zoo :: Foobar a -> Foobar HasZoo
>>>   
>>>       
>> Ouch #1: This appears to instantly disable deriving the Eq, Ord and Show 
>> instances I want. :-/
>>     
>
> Ah, yes, that is a pain.  Maybe try playing around with tools like
> Data.Derive?  I haven't played with them much myself so I don't know
> if they will help.
>   

Not nearly as annoying as this:

  data Foobar a where
    Foo :: X -> Y -> Foobar NoZoo
    Bar :: X -> Y -> Foobar NoZoo
    Zoo :: Foobar NoZoo -> Foobar Zoo

For some reason, if I do this I get endless type check errors. I have to 
change the top two back to Foobar a before it will work. *sigh*



More information about the Haskell-Cafe mailing list