我认为chr在其参数不是Unicode标量值的情况下,应该有一个函数可以工作但失败.
我通常用这种方式编写自己的函数:
toUnicode :: Int -> Maybe Char
toUnicode x
-- Ranges from "The Unicode Standard".
-- See definition D76 in Section 3.9, Unicode Encoding Forms.
| x >= 0 && x <= 0xD7FF = Just (chr x)
| x >= 0xE000 && x <= 0x10FFFF = Just (chr x)
| otherwise = Nothing
Run Code Online (Sandbox Code Playgroud)
但如果有更好的方法可以做到这一点会很好.