无法构建发送HTTP请求的简单应用程序

时间:2014-06-16 11:58:58

标签: macos haskell

我想用最简单的方式执行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 install xxx安装了.cabal文件中显示的所有库。

这是怎么回事?

更新

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"

2 个答案:

答案 0 :(得分:4)

所以问题是您的程序导入了Data.Conduit.Binary并未安装。它位于conduit-extra包中,因此您必须将其添加到依赖项中,并在需要时将其安装。

您的主要功能实际上并没有使用它,因此您只需删除导入即可修复当前错误。但是,在尝试构建时会出现新的错误,因为您还导入了未在cabal文件中列出的Data.Conduit。要修复此错误,请删除导入或将conduit添加到您的构建相关。

答案 1 :(得分:0)

现在似乎已经安装了两个(至少)版本的bytestring,并且不同的软件包不同意必须使用哪个版本。

我建议重新安装http-conduit