[Haskell-cafe] Deducing Show for GADTs

Joel Björnson joel.bjornson at gmail.com
Wed Jun 28 05:52:51 EDT 2006

Hi. I came a cross the following phenomena which, at least to me, occurs
of awkward. The code below :

data MyData a  where
  DC1 :: (Show a ) => a -> MyData a

instance Show (MyData a) where
  show (DC1 a ) = show a

yields the ghci error :
'Could not deduce (Show a) from the context (Show (MyData a))'

Adding a Show restriction for the instantiation as in

instance Show a => Show (MyData a ) where
  show (DC1 a ) = show a

makes the type checker happy. However,  this means that all parametrised
values over MyData must have a Show type which isn't necessarily what one

I would also like to point out that adding a 'wrapper type' as in

data Wrap a = Wrap a

data MyData a  where
  DC1 :: (Show a ) => a -> MyData (Wrap a)

instance Show (MyData a ) where
  show (DC1 a ) = show a

works fine. Even though 'Wrap' does not derive Show.

So, if anyone can give me some hints about the reason for this,  I will
appreciate it :)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/haskell-cafe/attachments/20060628/d661265f/attachment-0001.htm

More information about the Haskell-Cafe mailing list