[Haskell-cafe] Can we improve Show instance for non-ascii charcters?
david.feuer at gmail.com
Wed Feb 3 02:05:17 UTC 2016
Unfortunately, I don't think there is any way to do exactly this
without breaking the assumptions of a lot of existing code. But I
suspect you can work around the problem in a few different ways, one
of which strikes me as reasonable, if not quite perfectly accurate in
Write a function ushow that applies show to the given element, then
digs through the resulting string converting escape sequences
corresponding to valid Unicode codepoints into those codepoints.
On Tue, Feb 2, 2016 at 8:37 PM, Takayuki Muranushi <muranushi at gmail.com> wrote:
> Show instance for non-ascii characters prints their character codes.
> This is sad for Haskell users that speaks language other than English.
>> print $ [(++"'s dad"), (++"'s mom")] <*> ["Simon", "John"]
> ["Simon's dad","John's dad","Simon's mom","John's mom"]
>> print $ [(++"の父"), (++"の母")] <*> ["田中", "山田"]
> The function that needs improvement is showLitChar in GHC.Show, which
> currently prints any character larger than ASCII code 127 by its
> character code:
> 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.
> 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.
> Yesterday, I had a chance to teach Haskell (in Japanese,) and I had to
> use English in some of the most exciting examples, like the
> Applicative List example above. I would heartedly like to see GHC
> improve in these directions, so that we can make more happy learning
> materials on Haskell.
> Let me ask your opinions on what is the best way to do this (or is
> better not to do this), before I submit something to GHC Trac.
> -- Takayuki MURANUSHI
> -- RIKEN Advanced Institute for Computational Science
> -- http://nushio3.github.io/
> -- http://www.geocities.jp/takascience/
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe