[GHC] #7593: Unable to print exceptions of unicode identifiers

GHC ghc-devs at haskell.org
Mon Jul 28 03:08:59 UTC 2014


#7593: Unable to print exceptions of unicode identifiers
-------------------------------------+-------------------------------------
              Reporter:  dagit       |            Owner:
                  Type:  bug         |           Status:  new
              Priority:  normal      |        Milestone:  7.10.1
             Component:  Compiler    |          Version:  7.6.1
            Resolution:              |         Keywords:
      Operating System:  Windows     |     Architecture:  Unknown/Multiple
       Type of failure:  Incorrect   |       Difficulty:  Unknown
  warning at compile-time            |       Blocked By:
             Test Case:              |  Related Tickets:
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 This issue affects both Win32 consoles (e.g., cmd.exe) and mintty consoles
 (e.g., Cygwin and MSYS), but in different ways.

 In mintty consoles, the issue is easily fixed by setting the encoding of
 the file handle to {{{utf8}}}:

 {{{
 > putStrLn "→"
 *** Exception: <stdout>: hPutChar: invalid argument (invalid character)
 > import System.IO
 > hSetEncoding stdout utf8
 > putStrLn "→"
 →
 > getChar >>= putChar
 →
 Γ> getChar >>= putChar
 å> getChar >>= putChar
 Æ> getChar >>= putChar
 > hSetEncoding stdin utf8
 > getChar >>= putChar
 →
 →>
 }}}

 Fixing the issue on Win32 consoles is not as easy. One approach is to use
 the FFI to call the native API calls for Unicode output
 ([http://msdn.microsoft.com/en-
 us/library/windows/desktop/ms687401%28v=vs.85%29.aspx WriteConsoleW]) and
 input ([http://msdn.microsoft.com/en-
 us/library/windows/desktop/ms684961%28v=vs.85%29.aspx ReadConsoleInputW]).
 This is the approach that
 [https://github.com/judah/haskeline/blob/0f4ba2c51691f2031371c0bfadcd652abf57ad27/System/Console/Haskeline/Backend/Win32.hsc
 haskeline] takes, and it seems to work well:

 {{{
 > import System.Console.Haskeline
 > import Data.Maybe
 > runInputT defaultSettings (getInputChar "") >>= runInputT
 defaultSettings . outputStrLn . (:[]) . fromJust
 →
 →
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/7593#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list