我有一个发出http请求的函数,我需要访问返回的字节字符串。但是,我所拥有的monadic函数似乎无法返回与其IO分离的ByteString。
见下文:
executeRequest :: IO LAZ.ByteString
executeRequest = do
response <- simpleHttp "http://www.bbc.co.uk"
return (response)
html = executeRequest
extractBytesFromIO :: IO LAZ.ByteString -> LAZ.ByteString
extractBytesFromIO html = do
bytes <- html
bytes
以上不会编译,错误:
Couldn't match expected type ‘LAZ.ByteString’ with actual type ‘IO b0’
我需要将ByteString带出函数的本地范围,因此下面的代码不起作用:
html - executeRequest
extractBytesFromIO :: IO LAZ.ByteString
extractBytesFromIO = do
bytes <- html
let doStuff = //do stuff with bytes
html
有关extractBytesFromIO如何在没有IO上下文的情况下返回ByteString的任何建议?