2014-06-16 58 views
0

我想用最简单的方法执行HTTP请求。我决定使用管道。这是我的主文件:无法构建发送HTTP请求的简单应用程序

{-# LANGUAGE OverloadedStrings #-} 
import Network.HTTP.Conduit -- the main module 

-- The streaming interface uses conduits 
import Data.Conduit 
import Data.Conduit.Binary (sinkFile) 

import qualified Data.ByteString.Lazy as L 
import Control.Monad.IO.Class (liftIO) 

main :: IO() 
main = do 
    simpleHttp "http://www.example.com/foo.txt" >>= L.writeFile "foo.txt" 

而且.cabal:

executable AAA 
    main-is: Main.hs    
    hs-source-dirs: src 
    build-depends:  base ==4.6.*, text ==0.11.*, http-conduit, transformers, bytestring 

我不能建造它,错误的是:

$ cabal build 
Building AAA-0.1.0.0... 
Preprocessing executable 'AAA' for 
AAA-0.1.0.0... 

src/Main.hs:6:8: 
    Could not find module `Data.Conduit.Binary' 
    Perhaps you meant 
     Data.Conduit.List (needs flag -package conduit-1.1.4) 
     Data.Conduit.Lift (needs flag -package conduit-1.1.4) 
    Use -v to see a list of the files searched for. 

我已经安装了所有的库在.cabal文件中显示cabal install xxx

这是怎么回事?

更新:

Couldn't match type `L.ByteString' 
        with `bytestring-0.10.0.2:Data.ByteString.Lazy.Internal.ByteString' 
    Expected type: bytestring-0.10.0.2:Data.ByteString.Lazy.Internal.ByteString 
        -> IO() 
     Actual type: L.ByteString -> IO() 
    In the return type of a call of `L.writeFile' 
    In the second argument of `(>>=)', namely `L.writeFile "foo.txt"' 
    In a stmt of a 'do' block: 
     simpleHttp "http://www.example.com/foo.txt" 
     >>= L.writeFile "foo.txt" 

回答

4

所以,问题是,你的程序进口Data.Conduit.Binary未安装。它位于conduit-extra包中,因此如果要使用它,您必须将其添加到您的依赖项并进行安装。

虽然你的主要功能并没有真正使用它,所以你可以删除导入,它应该修复当前的错误。然而,当你尝试构建时,你会得到一个新的错误,因为你还导入了Data.Conduit,它也没有在你的cabal文件中列出。要解决此错误,请删除导入或将conduit添加到您的构建依赖项。

+0

你怎么知道它住在额外的管道中? –

+0

请看看我的更新,那里有另一个错误。 –

+0

这是一个奇怪的错误。我试过你的代码,并在我的电脑上编译。除了取消进口之外,您是否改变过其他任何内容?你也可以尝试重新安装沙箱,删除.cabal-sandbox目录,然后执行'cabal sandbox init',然后'cabal install --dependencies-only',然后尝试'cabal run'。 – Reite

0

好像现在你已经安装了两个(至少)bytestring版本,不同的软件包不同意使用哪一个版本。我建议重新安装http-conduit

相关问题