Hi. I came a cross the following phenomena which, at least to me, occurs kind
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 wants.
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 :)
Thanks
/Joel