Why `show` function can't make a character into a string itself?

Hello everyone, I’m trying to use show to turn a character 'z' into a string "z" in Haskell.

I try :

show 'z'

and Haskell give me :

"'z'"

This really makes me confused because in Haskell we have :

"z" == 'z' : []

But

"'z'" == '\'' : 'z' : '\'' : []

This confuses me because show function looks like breaks the expression into minimal parts and add parts into a list one by one with respect to the order and 'z' can’t be decomposed since it mean character z.

I think it’s natural to expect show 'z' to be "z" since show maps things to a string, but I don’t why Haskell doesn’t define show like that.

1 Like

show doesn’t just ‘map things to a string’; in well-behaved cases, it produces a ‘syntactically correct Haskell expression’. 'z' is the string representation of the character z, so that three-character string ' z ' is the correct result of show 'z', just like the three-character string " z " is the correct result of show "z".

4 Likes

Thanks! I think I got the point.