Haskell liftIO litter function type ErrorT String IO ()

I have a function that returns the type ErrorT String IO () . As long as the function works, liftIO places every line that performs IO. This creates a mess. Is there a way around this and still be able to abort the error?

+4
source share
1 answer

I assume this is the context of the question , so I will post a comment that I left there if you did not notice it:

If you use several specific functions, you can write a wrapper around them, for example. liftedPutStr = liftIO . putStr liftedPutStr = liftIO . putStr . You can even import originals and make your canceled version the same name if you want. In addition, a group of I / O operations that will not cause errors can be output to one separate function, which can be liftIO d only once. Does it help?

If you are not familiar with qualified imports, here putStr again as an example:

 import Prelude hiding (putStr) import qualified Prelude as P import Control.Monad.Trans putStr x = liftIO $ P.putStr x 

This will allow you to use the modified putStr in the converted IO just as you would normally use the real putStr in a simple IO .

+5
source

Source: https://habr.com/ru/post/1300541/


All Articles