7

I'd like to output non-ascii characters in WinGHCi, but this is what I get:

Prelude> "δ"
"\948"
Prelude> putStr "\948"
*** Exception: <stdout>: hPutChar: invalid argument (character is not in the code page)

I am using WinGHCi 7.0.3 on windows xp. What do I have to do so that WinGHCi prints a nice little delta?

gatoatigrado
  • 16,580
  • 18
  • 81
  • 143
Alex
  • 135
  • 7

2 Answers2

1

This is a WinGHCI bug. Use GHCI (the console, non-GUI version).

UPD: this is apparently not entirely correct (works for me with Greek letters and not e.g. Cyrillic).

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
1

Works on OSX!

Prelude> putStrLn "\948"
δ

Sounds like this is a windows problem with nothing to do with haskell...

pat
  • 12,587
  • 1
  • 23
  • 52
  • 3
    How's this not a Haskell problem? Surely GHCi should be able to interface with its underlying platform correctly. Other programs somehow manage this incredible feat. – n. m. could be an AI Sep 22 '11 at 16:51
  • 1
    I guess this doesn't work becuase of my current codepage. It's just that I don't know how to change it, or better: how to make GHCi use the new codepage. chcp commands don't solve the problem. – Alex Sep 22 '11 at 18:20
  • 4
    GHCi is giving the character to windows, and windows is complaining that it doesn't know how to deal with it since it is not in the current codepage. GHCi can't magically pick a codepage that does have a mapping for that character. At best, there should be a way to call the [SetConsoleOutputCP](http://msdn.microsoft.com/en-us/library/windows/desktop/ms686036(v=vs.85).aspx) function via the FFI, but it would be up to you to make the call, not GHCi. – pat Sep 22 '11 at 20:01
  • What is the FFl? And how do I call this function? – Alex Sep 23 '11 at 12:04
  • The Foreign Function Interface, a way for haskell code to call functions written in other languages. It is documented [here](http://www.haskell.org/onlinereport/haskell2010/haskellch8.html#x15-1490008). There is a wiki page [here](http://www.haskell.org/haskellwiki/Foreign_Function_Interface). I have never used it. You could post a new question. – pat Sep 23 '11 at 14:34
  • OK, you need [this](http://www.haskell.org/ghc/docs/latest/html/libraries/Win32-2.2.1.0/). Check out `System.Win32.Console.setConsoleOutputCP` – pat Sep 23 '11 at 14:43
  • thx, now I only need to find the codepage which supports all the characters I want to have. – Alex Sep 24 '11 at 18:56
  • Also works perfectly fine in Linux. Off course **it is** a typical Windows problem. Because http://www.utf8everywhere.org/ – ulidtko Jan 08 '15 at 16:22
  • Has this bug been reported? – CMCDragonkai May 11 '15 at 08:43