Assume I have a complex GADT which with many hidden type parameters as constructors:
data T where
A :: Num n => n -> T
B :: (Num n, Integral m) => n -> m -> T
C :: Floating a => [a] -> T
-- and so on
Z :: Num n => n -> n -> T
I want to make this datatype showable without having to manually write the instance. Problem is, that since Show
isn't a superclass of Num
anymore, adding a simple deriving instance Show T
isn't enough for the compiler to infer that it has to add Show
constraints to all the internal hidden type parameters.
For each hidden type parameter, it outputs something like
Could not deduce (Show n) arising from a use of 'showsPrec'
from the context Num n
bound by a pattern with constructor
A :: forall n. Num n => n -> T
...
Possible fix:
add (Show n) to the context of the data constructor 'A'
Adding a Show
constraint to the datatype isn't an option either, since it limits the possible inhabitants of T
. It seems like deriving instanec Show T
should introduce the constraint Show
on the hidden data types, although I am not sure.
How can I go about this?
Show
instance in a coherent way. – ThreeFxA
constructor is allowed to contain a non-showable number, how would you expect to show suchT
value? – chi