Fre*_*son 1 unicode haskell parsec utf-8 char
只需要了解与Parsec相关的内容.
parseTest (many1 alphaNum) "re2re1?"
"re2re1\916"
:t parseTest (many1 alphaNum)
parseTest (many1 alphaNum) :: Text.Parsec.Prim.Stream s Data.Functor.Identity.Identity Char =>
s -> IO ()
Run Code Online (Sandbox Code Playgroud)
因此,Unicode的输出(应该是UTF-8,因为我在OSX上)打印为十六进制(?)代码(应该是希腊三角形字符).现在,putChar不会在同一个ghci会话(和同一个终端)内进行相同的转换
Text.Parsec.Char> putChar '?'
?
Run Code Online (Sandbox Code Playgroud)
怎么会?它们应该只是'Char'类型以某种方式......?
这里的原因与方式有关show
并且putChar
已经实施.
?> show "re2re1?"
"\"re2re1\\916\""
?> mapM_ putChar "re2re1?"
re2re1?
Run Code Online (Sandbox Code Playgroud)
从源代码中可以看到Show
实例for Char
的定义如下:
instance Show Char where
showsPrec _ '\'' = showString "'\\''"
showsPrec _ c = showChar '\'' . showLitChar c . showChar '\''
showList cs = showChar '"' . showl cs
where showl "" s = showChar '"' s
showl ('"':xs) s = showString "\\\"" (showl xs s)
showl (x:xs) s = showLitChar x (showl xs s)
Run Code Online (Sandbox Code Playgroud)
putChar
像这样实现:
putChar :: Char -> IO ()
putChar c = hPutChar stdout c
Run Code Online (Sandbox Code Playgroud)
该parseTest
函数在内部使用print
本身内部使用的函数,这就是show
为什么要获得delta的Unicode代码点值的原因.
归档时间: |
|
查看次数: |
342 次 |
最近记录: |