将文字字符转换为Word8

Cli*_*ton 1 haskell ghc bytestring

ByteString的文档提供了以下代码示例:

breakByte :: Word8 -> ByteString -> (ByteString, ByteString)
breakByte 'c' "abcd"
Run Code Online (Sandbox Code Playgroud)

但是,当我写相同时,我得到以下错误(ideone):

Couldn't match expected type `GHC.Word.Word8'
            with actual type `Char'
Run Code Online (Sandbox Code Playgroud)

当然'c'Char,不是Word8.据推测,他们正在使用一些扩展,它允许fromInteger样式函数自动在Char文字上工作,但我不确定是什么.{-# LANGUAGE OverloadedStrings #-}似乎没有任何区别.

Don*_*art 6

只需导入模块的Char8版本.这些进行字节转换.请注意,这适用于8位字符.所以不要尝试将unicode数据放入其中.