Haskell's liftIO's litter functions of type ErrorT String IO ()
I have a function that returns type ErrorT String IO ()
. While the function works, liftIO
's litter every line that does IO. It makes for a开发者_开发技巧 mess. Is there any way to get around this and still have the ability to abort on error?
I assume this is the context of the question, so I'll repost the comment I left over there in case you didn't notice it:
If you use a few particular functions a lot, you could write a wrapper around them, e.g. liftedPutStr = liftIO . putStr
. You could even import the originals qualified and make your lifted version use the same name, if you wanted. Also, a group of IO actions that won't raise errors can be pulled out into a single, separate function that can then be liftIO
d just once. Does that help?
In case you're not familiar with qualified imports, here's putStr
again as an example:
import Prelude hiding (putStr)
import qualified Prelude as P
import Control.Monad.Trans
putStr x = liftIO $ P.putStr x
That should let you use the altered putStr
in a transformed IO
the same way you'd normally use the real putStr
in plain IO
.
精彩评论