lift package:relude

Lift a computation from the argument monad to the constructed monad.
Lift a binary function to actions. Some functors support an implementation of liftA2 that is more efficient than the default one. In particular, if fmap is an expensive operation, it is likely better to use liftA2 than to fmap over the structure and then use <*>. This became a typeclass method in 4.10.0.0. Prior to that, it was a function defined in terms of <*> and fmap.

Example

>>> liftA2 (,) (Just 3) (Just 5)
Just (3,5)
Lift a ternary function to actions.
Lift a computation from the IO monad. This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations (i.e. IO is the base monad for the stack).

Example

import Control.Monad.Trans.State -- from the "transformers" library

printState :: Show s => StateT s IO ()
printState = do
state <- get
liftIO $ print state
Had we omitted liftIO, we would have ended up with this error:
• Couldn't match type ‘IO’ with ‘StateT s IO’
Expected type: StateT s IO ()
Actual type: IO ()
The important part here is the mismatch between StateT s IO () and IO (). Luckily, we know of a function that takes an IO a and returns an (m a): liftIO, enabling us to run the program and see the expected results:
> evalStateT printState "hello"
"hello"

> evalStateT printState 3
3
Lifted versions of base functions. These functions are lifted in a sense that you can use them inside various monad transformers without adding liftIO calls explicitly. However, you still can use all these functions inside plain IO monad as usual.

Example

base

With the base function, you can easily work with these functions in the IO monad:
main :: IO ()
main = do
x <- getLine
print x
However, to work in MonadIO you already need to "lift" them:
main :: MonadIO m => m ()
main = do
x <- liftIO getLine
liftIO (print x)

relude

In the meantime, relude provides these function that can work in IO the same way:
main :: IO ()
main = do
x <- getLine
print x
But also allows you to work in the MonadIO monads more easily:
main :: MonadIO m => m ()
main = do
x <- getLine
print x