In what situations should liftIO be used? When I'm using ErrorT String IO, the lift function works to lift IO actions into ErrorT, so liftIO seems superfluous.
liftIO allows us to lift an IO action into a transformer stack that is built on top of IO and it works no matter how deeply nested the stack is.
From HaskellWiki. Lifting is a concept which allows you to transform a function into a corresponding function within another (usually more general) setting.
lift always lifts from the "previous" layer. If you need to lift from the second layer, you would need lift . lift and so on.
On the other hand, liftIO always lifts from the IO layer (which, when present, is always on the bottom of the stack). So, if you have more than 2 layers of monads, you will appreciate liftIO.
Compare the type of the argument in the following lambdas:
type T = ReaderT Int (WriterT String IO) Bool > :t \x -> (lift x :: T) \x -> (lift x :: T) :: WriterT String IO Bool -> T > :t \x -> (liftIO x :: T) \x -> (liftIO x :: T) :: IO Bool -> T
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With