GHC: Display of unicode characters

前端 未结 2 1927
自闭症患者
自闭症患者 2021-01-21 01:42

Further to my first question on the management of the unicode characters in the production of .exe file, this is also a bug in GHC?

> print \"Frère\"
\"Fr\\2         


        
相关标签:
2条回答
  • 2021-01-21 02:06

    Try

    > putStrLn "Frère"
    Frère      
    
    0 讨论(0)
  • 2021-01-21 02:11

    print x is equivalent to putStrLn (show x), where show converts a type of the Show class to a string representation.

    In your case, x already has the String type. One might think that the String implementation of show would simply return its argument unchanged, but actually it transforms it into an ASCII string literal token with the same syntax as used in Haskell source code. This is done by surrounding it with quotes and by escaping 'special' characters (basically whatever is not on your keyboard).

    So, this is not a bug but rather the expected behavior of print. If you want to output your string directly, use putStrLn instead.

    0 讨论(0)
提交回复
热议问题