printing unicode in Windows console: hPutChar error

Some of my poor misguided students are still using Windows, and when they run my (predecessor's) Haskell program which uses Unicode box drawing characters in its output, they get *** Exception <stdout>: hPutChar: invalid argument (invalid character) Another student told them to change the console encoding via magic: chcp.com 65001 but a bit of googling suggests that a "modern Windows console program" should be using the widechar API to print Unicode and things should Just Work. Does Haskell have a principled view about character encodings? Or does it just say "I do byte strings, it's the user's problem"? Decades ago I was all in favour of charset-agnosticism, but these days I tend to think "go Unicode, and leave the legacy Latin-1 etc. data as the user's problem" :) Julian. -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.

What version of GHC areyour students using? I believe sufficiently
recent versions of ghc (but I don't know which; this may require
9.2.1) have an RTS option to use a new I/O manager, which among other
things implements the widechar API for console I/O. The old I/O
manager does not support the widechar API, and the best that can be
done is the chcp hack.
On Fri, Nov 5, 2021 at 2:24 PM Julian Bradfield
Some of my poor misguided students are still using Windows, and when they run my (predecessor's) Haskell program which uses Unicode box drawing characters in its output, they get *** Exception <stdout>: hPutChar: invalid argument (invalid character)
Another student told them to change the console encoding via magic: chcp.com 65001
but a bit of googling suggests that a "modern Windows console program" should be using the widechar API to print Unicode and things should Just Work.
Does Haskell have a principled view about character encodings? Or does it just say "I do byte strings, it's the user's problem"?
Decades ago I was all in favour of charset-agnosticism, but these days I tend to think "go Unicode, and leave the legacy Latin-1 etc. data as the user's problem" :)
Julian.
-- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com

On Nov 5, 2021, at 12:34, Brandon Allbery
wrote: What version of GHC areyour students using? I believe sufficiently recent versions of ghc (but I don't know which; this may require 9.2.1) have an RTS option to use a new I/O manager, which among other things implements the widechar API for console I/O.
I found an email from Tamar https://mail.haskell.org/pipermail/ghc-devs/2020-July/019053.html that says the new Windows I/O manager is available in 8.12+, and is enabled with +RTS --io-manager=native

John Gleeson wrote:
On Nov 5, 2021, at 12:34, Brandon Allbery
wrote: What version of GHC areyour students using? I believe sufficiently recent versions of ghc (but I don't know which; this may require 9.2.1) have an RTS option to use a new I/O manager, which among other things implements the widechar API for console I/O.
I found an email from Tamar https://mail.haskell.org/pipermail/ghc-devs/2020-July/019053.html that says the new Windows I/O manager is available in 8.12+, and is enabled with +RTS --io-manager=native
thanks, Brandon and John. I imagine the students are using whatever was the obvious thing when they tried to install Haskell at start of semester. Looks like that would have been 8.10.7. I'll try to remember the RTS option for next year's students! Julian. -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.

On Fri, Nov 05, 2021 at 02:30:30PM -0600, John Gleeson via Haskell-Cafe wrote:
On Nov 5, 2021, at 12:34, Brandon Allbery
wrote: What version of GHC areyour students using? I believe sufficiently recent versions of ghc (but I don't know which; this may require 9.2.1) have an RTS option to use a new I/O manager, which among other things implements the widechar API for console I/O. I found an email from Tamar https://mail.haskell.org/pipermail/ghc-devs/2020-July/019053.html that says the new Windows I/O manager is available in 8.12+, and is enabled with +RTS --io-manager=native
Given that 8.12 doesn't exist I presume the meaning was "the version after 8.10" which is 9.0. Tom

Yes, 8.12 subsequently got re-versioned to 9.0.
On Sat, Nov 6, 2021 at 6:07 AM Tom Ellis
On Fri, Nov 05, 2021 at 02:30:30PM -0600, John Gleeson via Haskell-Cafe wrote:
On Nov 5, 2021, at 12:34, Brandon Allbery
wrote: What version of GHC areyour students using? I believe sufficiently recent versions of ghc (but I don't know which; this may require 9.2.1) have an RTS option to use a new I/O manager, which among other things implements the widechar API for console I/O. I found an email from Tamar https://mail.haskell.org/pipermail/ghc-devs/2020-July/019053.html that says the new Windows I/O manager is available in 8.12+, and is enabled with +RTS --io-manager=native
Given that 8.12 doesn't exist I presume the meaning was "the version after 8.10" which is 9.0.
Tom
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com
participants (4)
-
Brandon Allbery
-
John Gleeson
-
Julian Bradfield
-
Tom Ellis