发出HTTP请求时输入不匹配错误

时间:2014-06-16 17:15:17

标签: haskell http-conduit

尝试发出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"

错误是:

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"

我无法弄清楚如何解决它,因为错误的文字并没有真正意义。

1 个答案:

答案 0 :(得分:4)

bytestring包上有两个冲突的版本。试试ghc-pkg list bytestring。我建议你使用cabal沙箱来使用cabal沙箱。

另见"Couldn't match expected type with actual type" error when using Codec.BMP

BTW,ghc-7.8中的错误消息应该更好,请参阅https://ghc.haskell.org/trac/ghc/ticket/8278