In most OO languages that I'm familiar with, the toString String method is actually just an identification function. But in Haskell show , double quotes are added.
So, if I write some function, then
f :: Show a => [a] -> String f = concat . map show
works as expected for numbers
f [0,1,2,3] -- "0123"
but lines end with extra quotation marks
f ["one", "two", "three"] -- "\"one\"\"two\"\"three\""
when I really want "onetwothree" .
If I wanted to write f polymorphically, is there a way to do this only with the show constraint and without overriding the Show instance for String (if possible).
The best I can come up with is to create my own class like:
class (Show a) => ToString a where toString = show
and add an instance for everything?
instance ToString String where toString = id instance ToString Char where toString = pure instance ToString Int instance ToString Maybe ...etc
source share