I want to create a new type of data with Haskell and create the related Show
instances. I need to create the tuple Show instance with another delimiter than ,
.
I implemented this code (with the {-# LANGUAGE FlexibleInstances #-}
pragma):
newtype Data = Data Double
instance Show Data where
show (Data dat) = show dat
instance Show (Data,Data) where
show (Data d1,Data d2) = show d1++" "++show d2
instance Show (Data,Data,Data) where
show (Data d1,Data d2,Data d3) = show d1++" "++show d2++" "++show d3
Is it possible to automatically extend the Show instance to tuples of any size without manually creating the instances?
Note : I'm aware I could use concat $ intersperse " " ...
to intercalate things between list elements. But for many reasons I wish to use tuples rather than lists.