pepsiMaxFan
pepsiMaxFan

Reputation: 39

How to use show to print character without single quotes?

I'm defining an instance of the Show typeclass for a custom data type where in the single lettered character name is returned but it returns so with quotes.

More generally,

show 'a' returns as "'a'" in the console.

how do I return it as "a" (without the single quotes) but while still using show? Edit: Figured it out right after I posted the question. All I had to do was treat the char as a singleton list of char. show [a] returns what I want

Upvotes: 0

Views: 176

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476493

You can work with putStrLn :: String -> IO () to print the content of the string to the output channel:

putStrLn "a"

or if you work with a single character, you can use:

putStrLn ['a']

Upvotes: 2

Related Questions