Haskell: how to show tuples with more than 5 arguments
If you try to convert a long tuple with 6 or more components to a string in GHC, you get an error like
file.hs:17:5:
No instance for (Show ___)
arising from the 'deriving' clause of a data type declaration at file.hs:17:5
Probable fix: add an instance declaration for (Show ___)
When deriving the `Show' instance for type `___'
You can fix it with a show declaration for the number of arguments in your tuple. For example, this gives you support for 6-tuples:
instance (Show a, Show b, Show c, Show d, Show e, Show f) => Show (a,b,c,d,e,f) where
show (a,b,c,d,e,f) = "("++(show a)++", "++(show b)++", "++(show c)++", "++
(show d)++", "++(show e)++", "++(show f)++")"
0 Comments:
Post a Comment
<< Home