How to hack GHCi (or Hugs) so that it prints Unicode chars unescaped?

前端 未结 7 1905
情话喂你
情话喂你 2020-12-05 00:26

Look at the problem: Normally, in the interactive Haskell environment, non-Latin Unicode characters (that make a part of the results) are printed escaped, even if the locale

7条回答
  •  佛祖请我去吃肉
    2020-12-05 01:05

    You could switch to using the 'text' package for IO. E.g.

    Prelude> :set -XOverloadedStrings
    Prelude> Data.Text.IO.putStrLn "hello: привет"
    hello: привет
    

    The package is part of the standard Haskell distribution, the Haskell Platform, and provides an efficient packed, immutable Unicode text type with IO operations. Many encodings are supported.

    Using a .ghci file you could set -XOverloadStrings to be on by default, and write a :def macro to introduce a :text command that shows a value via text only. That would work.

提交回复
热议问题