[Haskell-cafe] Existentially-quantified constructors, Eq and Show

Joel Reymont joelr1 at gmail.com
Thu Dec 8 04:14:39 EST 2005

Did someone actually try compiling this? Here are the results:

data State a
     = Start
     | Stop
     | (Show a, Eq a) => State a
     deriving Show

     Can't make a derived instance of `Show (State a)'
     (`State' has existentially-quantified constructor(s))
     When deriving instances for type `State'

I do not want to do it the way Tomasz and John are suggesting below.
I need the user of my library to supply their own a and be able
to pattern match on it. In the library itself I just need Show and Eq a.

The following does the trick (compiles, works) but sucks in its  

data State a
     = Start
     | Stop
     | (Show a, Eq a) => State a

instance Eq a => Eq (State a) where
     (State a) == (State b) = a == b
     Start == Start = True
     Stop == Stop = True
     _ == _ = False

instance Show a => Show (State a) where
     show (State a) = show a
     show Start = "Start"
     show Stop = "Stop"

On Dec 8, 2005, at 8:36 AM, John Meacham wrote:

> On Thu, Dec 08, 2005 at 09:13:10AM +0100, Tomasz Zielonka wrote:
>> Shouldn't it be:
>>> data State
>>>     = Start
>>>     | Stop
>>>     | forall a . (Show a, Eq a) => State a
> ah. you are right. my bad.


More information about the Haskell-Cafe mailing list