此代码不进行类型检查:字节字符串预期不同的字节串
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
,但这会导致错误。
什么是进口限定的Data.ByteString.Lazy作为BS'? – viorior
@actionior它引发一个不同类型的错误。 – Sibi