3

このコードは型チェックを行いません:

import Network.HTTP.Conduit
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  resp <- simpleHttp "http://www.google.com"
  putStrLn $ BS.unpack resp

次のエラーをスローします。

Couldn't match expected type `BS.ByteString'
            with actual type `Data.ByteString.Lazy.Internal.ByteString'
In the first argument of `BS.unpack', namely `resp'
In the second argument of `($)', namely `BS.unpack resp'
In a stmt of a 'do' block: putStrLn $ BS.unpack resp
Failed, modules loaded: none.

これを修正するには?他の ByteString バリアントに変更しても機能しません。

simpleHttp関数のタイプは次のようになりますsimpleHttp :: Control.Monad.IO.Class.MonadIO m => String -> m Data.ByteString.Lazy.Internal.ByteString。そこで IO モナド内で ByteString を取得して試してみますunpackが、これはエラーになります。

4

1 に答える 1