2014-02-06 55 views
1

我一直在嘗試pipe-attoparsec,但一直沒有多少運氣。管道檢測問題-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. 

回答

0

看起來你正在使用 pipes-4.1.0一個版本 pipes-attoparsec(或其他pipes- *包我不能從錯誤消息中單獨確認),期望 pipes-4.0.2

如果您安裝了舊版本和最新版本,您很有可能需要使用ghc-pkg hide來隱藏舊版本的pipes-attoparsec(或其他pipes- *軟件包)。我不得不偶爾用其他軟件包來做這件事,但我不清楚cabal/ghci/ghc是如何進入需要的狀態。

使用ghc-pkg list | grep pipes-attoparsec查看您已安裝的版本並嘗試隱藏較舊的版本。如果您只安裝了舊版本,那麼請使用cabal install來獲取新版本。

Void VS X不匹配來自從 voidpipes-4.1.0方式。

+1

如果他安裝了「pipes-4.0.2」,然後安裝了「pipes-attoparsec」,然後安裝了「pipes-4.1.0」並隱藏了先前版本的管道,就會發生這種情況。只是不要安裝相同包的多個版本。壞事發生。 – Carl

+0

@Carl在一系列cabal install之後,我遇到過這種類型的問題,而且沒有隱藏任何軟件包。在Mac 10.8.5上。 – Davorak

1

您需要升級到最新的pipes-attoparsec,這會將其pipes依賴項限制爲4.1.*。如果列出您爲pipespipes-parsepipes-attoparsec安裝的版本,我可以爲您提供更詳細的信息。如果輸入ghc-pkg list | grep pipes即可。

+0

謝謝,這正是問題所在,並且在修復case表達式並添加一個類型簽名之後,它現在會進行類型檢查。 – user1219

+0

安裝新版本之前: 管-4.0.2 管-4.1.0 管 - 埃宋-0.2.1 管-attoparsec-0.3.1 管-字節字符串-2.0.0 管組-1.0。 0 pipes-network-0.6.1 pipes-network-tls-0.2.0 pipes-parse-2.0.2 pipes-parse-3.0.1 pipes-safe-2.0.1 – user1219

+0

是的,它看起來像什麼發生的是'pipes-attoparsec'是針對較舊的'pipes'編譯的,'pipes-parse'是針對較新的'pipes'編譯的。實際的衝突不是'X'類型的同義詞,而是它使用了兩個版本的'Proxy'。 –