Pregunta

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]?

¿Fue útil?

Solución

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top