Data.ByteString.Char8 不导出 stripSuffix

Data.ByteString.Char8 does not export stripSuffix

我正在处理 ByteString 流。我通过以下方式导入了 ByteString:

import qualified Data.ByteString as B

我可以调用 ByteString 库中的每个函数,例如:

reverseBS :: Monad m => Conduit B.ByteString m B.ByteString
reverseBS = CL.map B.reverse

这按预期工作。

我需要一个函数来从 ByteString 中删除结尾的换行符。我选择使用 stripSuffix from ByteString。我的代码如下所示:

removeNewline :: Monad m => Conduit B.ByteString m B.ByteString
removeNewline = CL.map $ B.stripSuffix "\n"

但是我的代码无法编译并出现以下错误:

Not in scope: ‘B.stripSuffix’

我已经尝试从 GitHub 安装最新版本的 ByteString 但这没有帮助。

编辑:

我注意到我的 ghc-pkg 列表有问题。它给我以下输出:

Thomass-MacBook-Pro:src ThomasVanhelden$ ghc-pkg list
/Applications/ghc-7.10.3.app/Contents/lib/ghc-7.10.3/package.conf.d
   Cabal-1.22.5.0
   array-0.5.1.0
   base-4.8.2.0
   bin-package-db-0.0.0.0
   binary-0.7.5.0
   bytestring-0.10.6.0
   containers-0.5.6.2
   deepseq-1.4.1.1
   directory-1.2.2.0
   filepath-1.4.0.0
   ghc-7.10.3
   ghc-prim-0.4.0.0
   haskeline-0.7.2.1
   hoopl-3.10.0.2
   hpc-0.6.0.2
   integer-gmp-1.0.0.0
   pretty-1.1.2.0
   process-1.2.3.0
   rts-1.0
   template-haskell-2.10.0.0
   terminfo-0.4.0.1
   time-1.5.0.1
   transformers-0.4.2.0
   unix-2.7.1.0
   xhtml-3000.2.1
/Users/ThomasVanhelden/.ghc/x86_64-darwin-7.10.3/package.conf.d
   WAVE-0.1.3
   abstract-deque-0.3
   abstract-par-0.3.3
   async-2.1.1
   attoparsec-0.13.1.0
   base16-bytestring-0.1.1.6
   base64-bytestring-1.0.0.1
   blaze-builder-0.4.0.2
   bytestring-0.10.8.2
   bytestring-lexing-0.5.0.2
   cereal-0.5.4.0
   chunked-data-0.3.0
   conduit-1.2.8
   conduit-combinators-1.0.8.3
   conduit-extra-1.1.15
   exceptions-0.8.3
   extensible-exceptions-0.1.1.4
   fail-4.9.0.0
   hashable-1.2.4.0
   lifted-base-0.2.3.8
   mmorph-1.0.9
   monad-control-1.0.1.0
   monad-par-0.3.4.8
   monad-par-extras-0.3.3
   mono-traversable-1.0.1
   mtl-2.2.1
   mwc-random-0.13.5.0
   network-2.6.3.1
   network-conduit-1.1.0
   parallel-3.2.1.0
   parallel-io-0.3.3
   parseargs-0.2.0.8
   primitive-0.6.1.0
   random-1.1
   resourcet-1.1.8.1
   scientific-0.3.4.9
   semigroups-0.18.2
   split-0.2.3.1
   stm-2.4.4.1
   streaming-commons-0.1.16
   tagged-0.8.5
   text-1.2.2.1
   transformers-base-0.4.4
   transformers-compat-0.5.1.4
   unix-compat-0.4.2.0
   unordered-containers-0.2.7.1
   vector-0.11.0.0
   vector-algorithms-0.7.0.1
   void-0.7.1
   word8-0.1.2
   zlib-0.6.1.2

看起来它正在两个不同的目录中寻找包,两个不同版本的 ByteString 可能是问题的原因。我该如何解决这个问题?有卸载 bytestring-0.10.6.0 的简单方法吗?

首先值得一提的是stripSuffix确实是在bytestring的0.18版本中引入的。引用 the changelog:

0.10.8.0 Duncan Coutts duncan@community.haskell.org May 2016

[etc.]

  • Added stripPrefix and stripSuffix for lazy and strict bytestrings

太伤心了,继续你的问题:

Is there a simple way to uninstall bytestring-0.10.6.0?

不,没有,因为,正如 ghc-pkg 输出告诉你的那样,0.10.6.0 版本是全局安装的包之一(即系统范围而不是比每个用户)。卸载它会破坏您之前安装的所有其他依赖于 bytestring 的软件包。当您从 GitHub 安装 bytestring 时,它会转到您的每个用户包数据库。为了避免进一步的头痛,我建议的第一件事是摆脱你安装的更新的 bytestring,其中:

ghc-pkg unregister bytestring-0.10.8.2

然后,要获得最新的 bytestring,您应该更新系统中的 Haskell 安装(例如,最新的 minimal Haskell Platform carries bytestring-0.10.8.1). Alternatively, you can use Stack 来管理多个适用于您的项目的 GHC 版本(以及适合它们的包数据库)。