我希望能够将ByteString
拆分成单词,如下所示:
import qualified Data.ByteString as BS
main = do
input <- BS.getLine
let xs = BS.split ' ' input
但是似乎 GHC 不能自己将字符字面量转换为 Word8
,所以我得到了以下结果:
Couldn't match expected type `GHC.Word.Word8'
with actual type `Char'
In the first argument of `BS.split', namely ' '
In the expression: BS.split ' ' input
Hoogle找不到类型签名为
Char -> Word8
的内容,而Word.Word8 ' '
是无效的类型构造函数。有什么解决方法吗?
ByteString
来处理文本!请改用Text
。 - Daniel WagnerByteString
更快吗? - AndrewText
支持 Unicode,因此您的字符串将在所有国家都是字符串。ByteString
用于二进制解析、原始内存访问,不能处理除 ASCII 或 Latin1 以外的任何内容。 - Don Stewart