【问题标题】:Typechecking problems with pipes-attoparsec管道 attoparsec 的类型检查问题
【发布时间】:2014-02-06 20:35:44
【问题描述】:

我一直在尝试 pipe-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.

【问题讨论】:

    标签: haskell attoparsec haskell-pipes


    【解决方案1】:

    您需要升级到最新的pipes-attoparsec,它将其pipes 依赖限制为4.1.*。如果您列出您为pipespipes-parsepipes-attoparsec 安装的版本,我可以为您提供更详细的信息,以了解这可能是如何出现的。如果你输入ghc-pkg list | grep pipes 就足够了。

    【讨论】:

    • 谢谢,这正是问题所在,在修复了 case 表达式并添加了类型签名之后,它现在可以进行类型检查了。
    • 安装新版本前:管道-4.0.2管道-4.1.0管道-aeson-0.2.1管道-attoparsec-0.3.1管道-字节串-2.0.0管道-组-1.0 .0 管道网络-0.6.1 管道网络-tls-0.2.0 管道解析-2.0.2 管道解析-3.0.1 管道安全-2.0.1
    • 是的,看起来发生的事情是pipes-attoparsec 是针对旧的pipes 编译的,而pipes-parse 是针对新的pipes 编译的。实际的冲突不是X 类型的同义词,而是它使用了Proxy 的两个版本。
    【解决方案2】:

    看起来你正在使用 pipes-4.1.0 有版本 pipes-attoparsec(或其他管道-* 包我无法仅从错误消息中确定。)期望 pipes-4.0.2.

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

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

    VoidX 不匹配来自 pipes-4.1.0 方式从 void 包。

    【讨论】:

    • 如果他安装pipes-4.0.2,然后安装pipes-attoparsec,然后安装pipes-4.1.0并隐藏以前版本的管道,就会发生这种情况。只是不要安装同一个包的多个版本。坏事发生了。
    • @Carl 在经历了一系列cabal installs 之后,我在没有隐藏包的情况下遇到了这类问题。在 mac 10.8.5 上。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    • 1970-01-01
    • 2020-07-14
    • 2019-03-27
    • 2019-09-02
    • 1970-01-01
    相关资源
    最近更新 更多