【问题标题】:RIO.ByteString.split not working as documentedRIO.ByteString.split 未按记录工作
【发布时间】:2020-09-04 19:41:42
【问题描述】:

尝试来自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"

我错过了什么?

【问题讨论】:

    标签: haskell rio


    【解决方案1】:

    文档取自Data.ByteString.Char8 modulesplit :: Char -&gt; ByteString -&gt; [ByteString] function。这将代码点 0-255 用作对应字节的 Char

    但是,您可以改用字节值。例如'a' 的字节值为 97,因此我们可以将其拆分为:

    Prelude> :set -XOverloadedStrings
    Prelude> import qualified RIO.ByteString as B
    Prelude B> B.split 97 "aXaXaXa"
    ["","X","X","X",""]
    

    【讨论】:

    • 太好了,谢谢!好的,基本上是文档中的一个错字,对吧?
    猜你喜欢
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多