本文介绍了GHC:显示unicode字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继续关于生成.exe文件中unicode字符管理的第一个问题,这也是GHC中的一个错误?

 >打印Frère
Fr\233re


解决方案

print x 相当于 putStrLn(show x),其中 show Show 类的类型转换为字符串表示形式。

在你的情况中,x已经有了 String 类型。有人可能会认为 show 的String实现只是简单地返回它的参数,但实际上它将它转换成ASCII字符串文字标记,其语法与Haskell源代码中使用的相同。这是通过用引号括住'特殊'字符(基本上不在键盘上)来完成的。

所以,这不是一个错误,而是预期的行为 print 。如果您想直接输出字符串,请改用 putStrLn


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\233re"
解决方案

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.

这篇关于GHC:显示unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 09:40