Show for Parameterized Type

Hello, I made a parameterized data type EW, which builds on a type of class Read and Show. When showing EW's it shall prefix the output with "EW:". data (Read a,Show a) => EW a = EW a x01 = EW 20 x02 = EW "Test" instance Show (EW a) where show (EW x) = show "EW:" ++ show x But I got a syntax error with this above at "show (EW x) = ...": No instance of (Read a) asrising a use of 'EW' in the pattern .... How can I formulate this show method correctly? I'd appreciate Your help Hartmut

On Aug 7, 2011, at 5:39 PM, Hartmut wrote:
How can I formulate this show method correctly?
instance (Show a, Read a) => Show (EW a) where show (EW x) = show "EW:" ++ show x ____________________ David Place Owner, Panpipes Ho! LLC http://panpipesho.com d@vidplace.com

David,
that was fast :-) Thank you for your help!
Hartmut
On Sun, Aug 7, 2011 at 11:47 PM, David Place
On Aug 7, 2011, at 5:39 PM, Hartmut wrote:
How can I formulate this show method correctly?
instance (Show a, Read a) => Show (EW a) where show (EW x) = show "EW:" ++ show x
____________________ David Place Owner, Panpipes Ho! LLC http://panpipesho.com d@vidplace.com

On Aug 7, 2011, at 5:54 PM, Hartmut wrote:
David, that was fast :-) Thank you for your help! Hartmut
Your welcome. ;-) I needed the break from what I was doing. I think I actually would like to add that normally i wouldn't put the class constraints in the data type definition. module Main where data EW a = EW a x01 = EW 20 x02 = EW "Test" instance (Show a) => Show (EW a) where show (EW x) = show "EW:" ++ show x instance (Read a) => Read (EW a) where read (etc...) ____________________ David Place Owner, Panpipes Ho! LLC http://panpipesho.com d@vidplace.com

My early intention was to limit the EW data type to showable/readable
values. It wanted it to only accepting one of these.
Now I have even two alternatives to choose :-)
Thanks
Hartmut
On Mon, Aug 8, 2011 at 12:02 AM, David Place
On Aug 7, 2011, at 5:54 PM, Hartmut wrote:
David, that was fast :-) Thank you for your help! Hartmut
Your welcome. ;-) I needed the break from what I was doing. I think I actually would like to add that normally i wouldn't put the class constraints in the data type definition.
module Main where
data EW a = EW a
x01 = EW 20 x02 = EW "Test"
instance (Show a) => Show (EW a) where show (EW x) = show "EW:" ++ show x
instance (Read a) => Read (EW a) where read (etc...)
____________________ David Place Owner, Panpipes Ho! LLC http://panpipesho.com d@vidplace.com
participants (2)
-
David Place
-
Hartmut