Show instance of Char should print literals for non-ascii printable charcters
Show instance for non-ascii characters prints their character codes. This is sad for Haskell users that speaks language other than English.
> 'A'
'A'
> 'Ä'
'\196'
> '漢'
'\28450'
> print $ [(++"'s dad"), (++"'s mom")] <*> ["Simon", "John"]
["Simon's dad","John's dad","Simon's mom","John's mom"]
> print $ [(++"の父"), (++"の母")] <*> ["田中", "山田"]
["\30000\20013\12398\29238","\23665\30000\12398\29238","\30000\20013\12398\27597","\23665\30000\12398\27597"]
The function that needs improvement is showLitChar in GHC.Show, which currently prints any character larger than ASCII code 127 by its character code:
http://haddock.stackage.org/lts-5.1/base-4.8.2.0/src/GHC-Show.html
showLitChar :: Char -> ShowS
showLitChar c s | c > '\DEL' = showChar '\\' (protectEsc isDec (shows
(ord c)) s)
On the other hand, there is GHC.Unicode.isPrint, the predicate for printable Unicode characters, that is calling on a foreign function u_iswprint for the knowledge.
https://hackage.haskell.org/package/base-4.8.2.0/docs/src/GHC.Unicode.html#isPrint
I think one of the solution is to import and call u_iswprint from GHC.Show, too, but I don't know it's against any design choices.
Trac metadata
Trac field | Value |
---|---|
Version | 7.10.3 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |