[Haskell-cafe] How to input Unicode string in Haskell program?
Semyon Kholodnov
joker.vd at gmail.com
Fri Feb 22 17:17:57 CET 2013
I would like to point out again that I am talking about Windows. I
don't care about Linux—I'm sure you already threw away all those
stupid legacy one- and multibyte code pages and migrated to UTF8
completely, but that's not quite the current state of Windows. Console
still doesn't cope with Unicode quite well.
Anyway, the problem is partially solved: I patched my WinGHCi so it no
longer chokes on Unicode input, and as for compiled .exe... I'll see.
2013/2/22, Jon Fairbairn <jon.fairbairn at cl.cam.ac.uk>:
> Alexander V Vershilov <alexander.vershilov at gmail.com> writes:
>
>> The problem is that Prelude.getLine uses current locale to load
>> characters:
>> for example if you have utf8 locale, then everything works out of the box:
>>
>>> $ runhaskell 1.hs
>>> résumé 履歴書 резюме
>>> résumé 履歴書 резюме
>>
>> But if you change locale you'll have error:
>>
>>> LANG="C" runhaskell 1.hs
>>> résumé 履歴書 резюме
>>> 1.hs: <stdin>: hGetLine: invalid argument (invalid byte sequence)
>
> That seems to be correct behaviour: the only way to know the
> meaning of the bits input by a user is what encoding the user
> says they are in.
>
> But in general this issue is an instance of inheriting sins from
> the OS: the meaning of the bit pattern in a file should be part
> of the file, but we are stuck with OSs that use a global
> variable (which should be anathema to Haskell). So if user A has
> locale set one way and inputs a file and sends the filename to
> user B on the same system, user B might well see something
> completely different to A when looking at the file.
>
>> To force haskell use UTF8 you can load string as byte sequence
>> and convert it to UTF-8 charecters
>
> but of course, the programmer can only hope that utf-8 will work
> here. If the user is typing in KOI-8R, reading it as utf-8 is
> going to be wrong.
> --
> Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list