So I have a data type
data SomeType a =
Type a |
Mix (SomeType a) (SomeType a)
This my show instance for SomeType
instance (Show a) => Show (SomeType a) where
show (Type a) = show a
show (Mix a b) = "(" ++ show a ++ " " ++ show b ++ ")"
So
Mix (Type 5) (Type 4)
would give me
(5 4)
Now I want to have
read "(3 4)" :: SomeType Int
produce
(3 4)
or
read "(a b)" :: SomeType Char
produce
(a b)
I am lost at how to use the Read class.
SomeType Charis not whatshow (Mix (Type 'a') (Type 'b'))would have generated.deriving (Show, Read)after the type delcaration. While they won't produce your output and input, they are a standard way of showing (and sometimes reading) values, which is why you should use them instead of your own instances. If you want to show them in a different way, use a separate function and call itrenderor so.