这是我的代码:
import qualified System.IO as IO
writeSurrogate :: IO ()
writeSurrogate = do
IO.writeFile "/home/sibi/surrogate.txt" ['\xD800']
执行上面的代码会报错:
text-tests: /home/sibi/surrogate.txt: commitBuffer: invalid argument (invalid character)
原因是 GHC 本身阻止了它,因为它们是代理代码点:https ://github.com/ghc/ghc/blob/21f0f56164f50844c2150c62f950983b2376f8b6/libraries/base/GHC/IO/Encoding/Failure.hs#L114
我想写一些需要这些数据的测试文件。现在,我正在使用 Python 来实现我想要的 - 但我很想知道是否有办法(使用 Haskell 的解决方法)来实现这一目标。