[Haskell-beginners] Manage the type of a variable in the show implementation

Christian Sperandio christian.sperandio at gmail.com
Wed Jul 23 12:20:23 UTC 2014


Hi,

I wrote this kind of code:

data DataLog a = SingleData a
               | MultipleData [a]

instance (Show a) => Show (DataLog a) where
    show (SingleData v) = show v
    show (MultipleData vs) = join "|" vs
        where join _ [] = []
              join _ (x:[]) = show x
              join s (x:xs) = show x ++ s ++ join s xs

It works but when the DataLog is String typed I got this result:
"My Test"|"Another Value"

I'd prefer have:
My Test|Another Value

I know the quote problem comes from the show function on String value.
How could I do a show for no-string values and return directly the value
for strings?

Thanks.

Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140723/1f148f48/attachment.html>


More information about the Beginners mailing list