Hi. I came a cross the following phenomena which, at least to me, occurs kind<br>
of awkward. The code below :<br>
<br>
data MyData a where<br>
DC1 :: (Show a ) => a -> MyData a<br>
<br>
instance Show (MyData a) where<br>
show (DC1 a ) = show a<br>
<br>
yields the ghci error : <br>
'Could not deduce (Show a) from the context (Show (MyData a))'<br>
<br>
Adding a Show restriction for the instantiation as in<br>
<br>
instance Show a => Show (MyData a ) where<br>
show (DC1 a ) = show a<br>
<br>
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 wants.<br>
<br>
I would also like to point out that adding a 'wrapper type' as in<br>
<br>
data Wrap a = Wrap a<br>
<br>
data MyData a where<br>
DC1 :: (Show a ) => a -> MyData (Wrap a)<br>
<br>
instance Show (MyData a ) where<br>
show (DC1 a ) = show a <br>
<br>
works fine. Even though 'Wrap' does not derive Show.<br>
<br>
So, if anyone can give me some hints about the reason for this, I will appreciate it :)<br>
<br>
Thanks<br>
/Joel