[GHC] #11529: Show instance of Char should print literals for non-ascii printable charcters

GHC ghc-devs at haskell.org
Wed Feb 3 02:11:11 UTC 2016


#11529: Show instance of Char should print literals for non-ascii printable
charcters
-------------------------------------+-------------------------------------
           Reporter:  nushio         |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  7.10.3
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Show instance for non-ascii characters prints their character codes.
 This is sad for Haskell users that speaks language other than English.

 {{{#!hs
 > '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

 {{{#!hs
 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.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11529>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list