There are ways of doing what you ask for, but it is unsafe. Therefore, I think you should be looking at the problem the other way around. In staid of getting the list out of IO
, you should lift your pure function into IO
.
Let's say you wanted to get the list from DB and apply some pure function to it, then you could do the following:
yourFunc = do
list <- getListFromDB
return (myPureFunction List)
or if you want to print the result afterwords:
yourFunc = do
list <- getListFromDB
print (myPureFunction List)
In general, in order to calculate a pure
result inside of the IO monad you can use let:
yourFunc = do
list <- getListFromDB
let result = myPureFunction list
return result
or more compact:
import Control.Monad((=<<))
import Control.Applicative((<$>))
yourFunc = print =<< myPureFunction <$> getListFromDB