[Haskell-cafe] Proposal: new function for lifting
Nick Vanderweit
nick.vanderweit at gmail.com
Fri Sep 27 22:21:24 CEST 2013
Sorry for sending this twice; I didn't reply to the list initially.
I thought people [1] were generally talking about lift from
Control.Monad.Trans:
class MonadTrans t where
lift :: Monad m => m a -> t m a
The idea being that lifting through a monad stack feels tedious. The
proposed solution is to use instances to do the lifting for you, like in
mtl. So we've got instances like:
MonadState s m => MonadState s (ReaderT r m)
Which let you automatically lift get/put/modify up a stack, without doing
any work.
This is different from liftM*, which are about applying a pure function
to monadic arguments. This can be done quite nicely with (<$>) and (<*>)
from Data.Functor and Control.Applicative, respectively. Your first
example can be written:
(+) <$> (Just 42) <*> Nothing
Nick
[1]
http://blog.ezyang.com/2013/09/if-youre-using-lift-youre-doing-it-wrong-probably/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 295 bytes
Desc: OpenPGP digital signature
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130927/be2a616b/attachment.pgp>
More information about the Haskell-Cafe
mailing list