I have a function that makes a http request, I need to access the returned byte string. However, the monadic function I have doesn't seem to be able to return the ByteString separated from its IO.
See below:
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
The above won't compile, with an error:
Couldn't match expected type ‘LAZ.ByteString’ with actual type ‘IO b0’
I need to bring the ByteString out of the local scope of the function, so the below will not work:
html - executeRequest
extractBytesFromIO :: IO LAZ.ByteString
extractBytesFromIO = do
bytes <- html
let doStuff = //do stuff with bytes
html
Any suggestions on how extractBytesFromIO can return the ByteString without the IO context?