Reputation: 2017
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]
?
Upvotes: 10
Views: 269
Reputation: 139900
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
Upvotes: 13