此代码不进行类型检查:
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 monad 中获取 ByteString 并尝试unpack
它,但这会导致错误。