1

我一直在尝试管道-attoparsec,但运气不佳。

在相对简单的代码中(似乎是),似乎 Void 和 X 之间存在类型不匹配。从我在库中读到的内容(在某些时候这将成为类型同义词),我不确定如何解释类​​型错误。

测试代码:

{-# LANGUAGE OverloadedStrings,RankNTypes #-}
module Main where

import qualified Data.Attoparsec.Char8 as A

import qualified Pipes as P
import qualified Pipes.Attoparsec as PA        
import qualified Pipes.ByteString as PB
import qualified Pipes.Parse  as PP

passthrough :: A.Parser PB.ByteString
passthrough = A.takeWhile (\s->True)

f :: Monad m => PP.StateT (P.Producer PB.ByteString m r) m (Either String  String)
f = do
  r <- PA.parse passthrough
  return $ case r of
    Left e -> Left "a"
    Right (_,r1) -> Right "b"

g = PP.evalStateT f PB.stdin

h = P.runEffect g

这会导致错误:

P.hs:16:8:
    Couldn't match type `pipes-4.0.2:Pipes.Internal.Proxy
                           Data.Void.Void () () PB.ByteString m r0'
                  with `P.Proxy P.X () () PB.ByteString m r'
    Expected type: PP.StateT
                     (PP.Producer PB.ByteString m r)
                     m
                     (Either PA.ParsingError (Int, PB.ByteString))
      Actual type: PP.StateT
                     (pipes-4.0.2:Pipes.Core.Producer PB.ByteString m r0)
                     m
                     (Either PA.ParsingError (Int, PB.ByteString))
    In the return type of a call of `PA.parse'
    In a stmt of a 'do' block: r <- PA.parse passthrough
    In the expression:
      do { r <- PA.parse passthrough;
           return
           $ case r of {
               Left e -> Left "a"
               Right (_, r1) -> Right "b" } } Failed, modules loaded: none.
4

2 回答 2

1

您需要升级到最新的pipes-attoparsec,这将其pipes依赖限制为4.1.*. 如果您列出您为pipespipes-parsepipes-attoparsec. 如果你打字ghc-pkg list | grep pipes就足够了。

于 2014-02-06T12:35:44.970 回答
0

看起来您正在使用 带有 pipelines-attoparsec 版本的管道4.1.0(或另一个管道 - * 包,我不能仅从错误消息中确定。)预期 管道 4.0.2

如果您同时安装了旧版本和最新版本,则很有可能需要使用ghc-pkg hide隐藏旧版本的管道-attoparsec(或其他管道-* 包)。我偶尔不得不对其他软件包执行此操作,但我不清楚 cabal/ghci/ghc 如何进入必要的状态。

用于ghc-pkg list | grep pipes-attoparsec查看您安装了哪些版本并尝试隐藏较旧的版本。如果你只安装了旧的,那么使用 cabal install 来获取新的。

VoidvsX不匹配来自 void包中的管道 4.1.0方式 。

于 2014-02-06T08:20:36.733 回答