RIO.ByteString.split 未按记录工作
RIO.ByteString.split not working as documented
尝试 split docs 中的示例:
$ stack ghci
...
Prelude> :set -XOverloadedStrings
Prelude> import qualified RIO.ByteString as B
Prelude B> B.split 'a' "aXaXaXa"
<interactive>:3:9: error:
• Couldn't match expected type ‘GHC.Word.Word8’
with actual type ‘Char’
• In the first argument of ‘B.split’, namely ‘'a'’
In the expression: B.split 'a' "aXaXaXa"
In an equation for ‘it’: it = B.split 'a' "aXaXaXa"
我错过了什么?
文档取自split :: Char -> ByteString -> [ByteString]
function of the Data.ByteString.Char8
module。这使用代码点 0-255 作为相应字节的 Char
。
但是您可以改用字节值。例如 'a'
的字节值为 97,因此我们可以将其拆分为:
Prelude> :set -XOverloadedStrings
Prelude> import qualified RIO.ByteString as B
Prelude B> B.split 97 "aXaXaXa"
["","X","X","X",""]
尝试 split docs 中的示例:
$ stack ghci
...
Prelude> :set -XOverloadedStrings
Prelude> import qualified RIO.ByteString as B
Prelude B> B.split 'a' "aXaXaXa"
<interactive>:3:9: error:
• Couldn't match expected type ‘GHC.Word.Word8’
with actual type ‘Char’
• In the first argument of ‘B.split’, namely ‘'a'’
In the expression: B.split 'a' "aXaXaXa"
In an equation for ‘it’: it = B.split 'a' "aXaXaXa"
我错过了什么?
文档取自split :: Char -> ByteString -> [ByteString]
function of the Data.ByteString.Char8
module。这使用代码点 0-255 作为相应字节的 Char
。
但是您可以改用字节值。例如 'a'
的字节值为 97,因此我们可以将其拆分为:
Prelude> :set -XOverloadedStrings
Prelude> import qualified RIO.ByteString as B
Prelude B> B.split 97 "aXaXaXa"
["","X","X","X",""]