[Haskell-beginners] Print Unicode in String

Daniel Fischer daniel.is.fischer at web.de
Wed Jul 28 18:11:30 EDT 2010


On Wednesday 28 July 2010 23:43:01, dan portin wrote:
> Hi,
>
> Perhaps I'm missing something, but I haven't found an answer to this
> question in the textbook I have been using (Thompson) or through
> Google/Hoogle: can a String include Unicode characters?

Yes. A Char is a unicode code-point.

> For instance, if
> I am defining an instance of Show Expr, where Expr models simple
> arithmetic expressions (or Show Seq, where Seq models a sequent

Don't call it Seq, that's already used for sequences in Data.Sequence.

> calculus, and so forth), could I define a function *show Pi* = U+03C0 or

You need a different syntax, show Pi = "\x03C0"

> *show Delta* = U+0395?

show Delta = "\x0394"

> Perhaps the answer is obvious, but I haven't been able to find it.

However, if your locale is not utf-8 or you're using a pre-6.12 GHC, output 
might be garbled, then you'd have to use System.IO.UTF8.putStrLn to print.



More information about the Beginners mailing list