Mike ... try this ...extend it to however long tuples you have


data MyData = Foo | Bar deriving Show

main = print (Foo,Foo,Foo,Foo,Foo,Foo)

instance (Show tv1, Show tv2, Show tv3, Show tv4, Show tv5 , Show tv6) =>
Show (tv1,tv2,tv3,tv4,
tv5,tv6) where
        showsPrec p (v1,v2,v3,v4,v5,v6) = showChar '(' . shows v1 . showChar
',' .
                                                         shows v2 . showChar
',' .
                                                         shows v3 . showChar
',' .
                                                         shows v4 . showChar
',' .
                                                         shows v5 . showChar
',' .
                                                         shows v6 . showChar
')'

instance (Read tv1, Read tv2, Read tv3, Read tv4, Read tv5 , Read tv6) =>
Read (tv1,tv2,tv3,tv4,
tv5,tv6) where
        readsPrec p = readParen False
                        (\s0 -> [((v1,v2,v3,v4,v5,v6),s6A) | ("(",s1) <- lex
s0,
                                                           (v1,s1A) <- reads
s1,
                                                           (",",s2) <- lex
s1A,
                                                           (v2,s2A) <- reads
s2,
                                                           (",",s3) <- lex
s2A,
                                                           (v3,s3A) <- reads
s3,
                                                           (",",s4) <- lex
s3A,
                                                           (v4,s4A) <- reads
s4,
                                                           (",",s5) <- lex
s4A,
                                                           (v5,s5A) <- reads
s5,
                                                           (",",s6) <- lex
s5A,
                                                           (v6,s6A) <- reads
s6,
                                                           (")",s3) <- lex
s2A ])



> -----Original Message-----
> From: Mike Jones [mailto:[EMAIL PROTECTED]]
> Sent: 09 May 2000 14:54
> To: 'Chris Angus'
> Cc: [EMAIL PROTECTED]
> Subject: RE: Showing tuples
> 
> 
> Chris,
> 
> Yes, I do derive Show for MyData. I was surprised it did not work.
> 
> Mike
> 
> -----Original Message-----
> From: Chris Angus [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, May 09, 2000 12:57 AM
> To: 'Mike Jones'; [EMAIL PROTECTED]
> Subject: RE: Showing tuples
> 
> 
> Do you derive Show for MyData?
> 
> > -----Original Message-----
> > From: Mike Jones [mailto:[EMAIL PROTECTED]]
> > Sent: 09 May 2000 05:58
> > To: [EMAIL PROTECTED]
> > Subject: Showing tuples
> > 
> > 
> > Hi,
> > 
> > I am having trouble with Show and tuples.
> > 
> > I have a data structure, say:
> > 
> > data MyData = ...
> > 
> > And a value, say:
> > 
> > value = (MyData..., MyData..., MyData)
> > 
> > Then try to:
> > 
> > show value
> > 
> > I get a compiler message from ghc 4.05 that says:
> > 
> > No instance for `Show (MyData, MyData, MyData)...
> > 
> > What is the best way to deal with this problem?
> > 
> > Thanks,
> > 
> > Mike
> > 
> > 
> 
> 
> 

Reply via email to