我想用最简单的方法执行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