how can I remove the quotes from a string in the output of a file in haskell

1
writeFile "CRITICOS.txt" (show ([head nodocritico]))

but in the file shows it to me so ["C"] and I want to put it so [C] as I could remove the double quotes?

    
asked by Efrainrodc 29.06.2017 в 04:51
source

1 answer

1

Instance show for [a] is based on the definition of show for a and Show String always puts double quotes around String .

You can omit the double quotes by writing your own version of the function:

import Data.List

myShow :: [String] -> String
myShow strs = concat [ "[", intercalate "," strs, "]" ]

You can also reuse the instance Show [a] using a newtype wrapper to change the instance that ghc selects:

newtype NoDoblesComillas = NDC { getString :: String }

instance Show NoDoblesComillas where
  show = getString -- usando el string directamente

myShow :: [String] -> String
myShow = show . fmap NDC
    
answered by 29.06.2017 / 14:06
source