我想用最簡單的方法執行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"
你怎麼知道它住在額外的管道中? –
請看看我的更新,那裏有另一個錯誤。 –
這是一個奇怪的錯誤。我試過你的代碼,並在我的電腦上編譯。除了取消進口之外,您是否改變過其他任何內容?你也可以嘗試重新安裝沙箱,刪除.cabal-sandbox目錄,然後執行'cabal sandbox init',然後'cabal install --dependencies-only',然後嘗試'cabal run'。 – Reite