3

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

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

4

1 回答 1

4

bytestring您在包上有两个冲突的版本。试试ghc-pkg list bytestring。我建议您对代码进行 cabalize 并使用 cabal 沙箱。

另请参阅使用 Codec.BMP 时出现“无法将预期类型与实际类型匹配”错误

顺便说一句,错误消息应该更好ghc-7.8,请参阅https://ghc.haskell.org/trac/ghc/ticket/8278

于 2014-06-16T17:30:26.080 回答