[Haskell-cafe] How to use Unicode strings?

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Sat Nov 22 14:16:13 EST 2008


On Sat, 2008-11-22 at 10:02 -0800, Don Stewart wrote:

> Use the UTF8 printing functions,
> 
>     import qualified System.IO.UTF8 as U
> 
>     main = U.putStrLn "Ну и где этот ваш хвалёный уникод?"
> 
> Running this,
> 
>     *Main> main
>     Ну и где этот ваш хвалёный уникод?


This upsets me. We need to get on with doing this properly. The
System.IO.UTF8 module is a useful interim workaround but we're not using
it properly most of the time.

It is right when you're working with a text file that you know to be in
the UTF-8 format. For example .cabal files are UTF-8, irrespective of
the platform or the system locale.

It is not right when working with the terminal. The encoding of the
terminal is given by the locale. We cannot statically declare that it is
UTF-8.

The right thing to do is to make Prelude.putStrLn do the right thing. We
had a long discussion on how to fix the H98 IO functions to do this
better. We just need to get on with it, or we'll end up with too many
cases of people using System.IO.UTF8 inappropriately.

For the case where System.IO.UTF8 is right we probably still want a more
general solution, like a handle setting for the encoding.

Duncan



More information about the Haskell-Cafe mailing list