[英]Unable to build a simple application sending a HTTP request
我想使用最簡單的方法執行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"
因此,問題在於您的程序導入了未安裝的Data.Conduit.Binary
。 它位於conduit-extra
軟件包中,因此,如果要使用它,則必須將其添加到依賴項中並進行安裝。
但是,您的main函數實際上並沒有使用它,因此您只需刪除導入即可,它應該可以解決當前錯誤。 但是,在嘗試構建時會收到一個新錯誤,因為您還導入了未在cabal文件中列出的Data.Conduit
。 要解決此錯誤,請刪除導入或將conduit
添加到構建依賴項。
好像現在您已經安裝了兩個(至少) bytestring
版本,並且不同的軟件包對於必須使用哪個軟件包並不一致。
我建議重新安裝http-conduit
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.