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

Cale Gibbard cgibbard at gmail.com
Thu Dec 8 04:42:46 EST 2005


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

Putting the class context on the data constructor like that wasn't
doing you any more good than this way, and was causing ghc to think
that the constructor was existentially quantified.

 - Cale

On 08/12/05, Joel Reymont <joelr1 at gmail.com> wrote:
> Did someone actually try compiling this? Here are the results:
>
> data State a
>      = Start
>      | Stop
>      | (Show a, Eq a) => State a
>      deriving Show
>
> foo.hs:1:5:
>      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
> verbosity:
>
> 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.
>
> --
> http://wagerlabs.com/
>
>
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list