I am new to monad transformers, so sorry easy question. I have value val :: MaybeT IO String
and function fn :: String -> IO [String]
. So after binding, I have val >>= liftM fn :: MaybeT IO (IO [String])
. How can I remove duplicate IO monad and get result of type MaybeT IO [String]
?
Use lift
(or liftIO
) instead of liftM
.
> :t val >>= lift . fn
val >>= lift . fn :: MaybeT IO [String]
liftM
is for applying pure functions in a monad. lift
and liftIO
are for lifting actions into a transformer.
liftM :: Monad m => (a -> b) -> m a -> m b
lift :: (Monad m, MonadTrans t) => m a -> t m a
liftIO :: MonadIO m => IO a -> m a
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.