[Haskell-cafe] GHC rendering of non-ASCII characters configurable?

Richard Cobbe cobbe at ccs.neu.edu
Tue Jul 31 13:01:25 CEST 2012

On Mon, Jul 30, 2012 at 11:45:38PM +1000, Ivan Lazar Miljenovic wrote:
> On 30 July 2012 04:04, Richard Cobbe <cobbe at ccs.neu.edu> wrote:
> > I'm working on an application that involves processing a lot of Unicode
> > data, and I'm finding the built-in Show implementation for Char to be
> > really inconvenient.  Specifically, it renders all characters at U+0080 and
> > above with decimal escapes:
> >
> >     Prelude> '\x80'
> >     '\128'
> >
> > This is annoying because all of the Unicode charts give the code points in
> > hex, and indeed the charts are split into different PDFs at numbers that
> > are nice and round in hex but not in decimal.  So in order to figure out
> > which character I'm looking at, I have to convert back to hex and then look
> > it up in the charts.
> Can I ask what you're doing here? Are you printing individual
> characters or entire chunks of text?

Mostly, I'm working with expressions of type String, rather than Text; the
Char above was merely an example to demonstrate the problem.  The two I/O
cases that most concern me are evaluating a String expression at the GHCi
REPL, and working with HUnit test cases built around String expressions.

I suppose I could wrap putStrLn around all string exprs at the repl, but a)
that's a pain; b) it's important for this app that I be able to distinguish
between precomposed characters and combining characters; and c) some of the
characters I'm dealing with are very similar in my terminal fonts, such as
U+1F00 and U+1F01.  It's much nicer to be able to just see the code points.

The other problem is with HUnit tests.  When a test fails (under runTestTT,
anyway) you get a diagnostic printed to stdout.  I'm not sure exactly what
logic HUnit uses to produce these error messages, but it's almost certainly
calling 'show' on the underlying strings.  So there's no place, as far as I
know, where I can insert a call to putStrLn.


More information about the Haskell-Cafe mailing list