Search code examples
haskellhttp-conduit

Type mismatch error in making HTTP request


Trying to make a HTTP request, I got the error:

{-# 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"

The error is:

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"

I can't figure out how to solve it because the text of the error doesn't really make sense.


Solution

  • You have two conflicting versions on bytestring package. Try ghc-pkg list bytestring. I'd suggest you to cabalize your code and use cabal sandbox.

    See also "Couldn't match expected type with actual type" error when using Codec.BMP

    BTW, the error message should be better in ghc-7.8, see https://ghc.haskell.org/trac/ghc/ticket/8278