concrete functor and monad transformers
#49Maybe to MaybeT
Can the following function be added to Control.Monad.Trans.Maybe?
liftMaybe :: Applicative m => Maybe a -> MaybeT m a
When using MaybeT, it's quite common to want to lift Maybe a to MaybeT m a. This is the equivalent of except, state, etc. for other transformers.
In the errors package, these have existed for years as:
hoistMaybe :: Monad m => Maybe b -> MaybeT m bIgnoring the naming bikeshed, I really think this ought to be in transformers.
The
Applicativeconstraint is the right one these days.Yes, the Applicative constraint is fine for new definitions.
This can be generalized to
Alternative m => Maybe a -> m a, in which case I would expect to find it in base first, but it would still be useful to have it exported in transformers, in one form or another, if only for discoverability. I have started a thread on the libraries mailing list.https://mail.haskell.org/pipermail/libraries/2018-April/028690.html
That's a different function from what was proposed here, I think:
liftMaybe :: Applicative m => Maybe a -> MaybeT m a liftMaybe = MaybeT . pure
It can be generalised further into
(Alternative m, Foldable f) => f a -> m a, and I'm calling itfoldAlt- status set to closed
fixed, thanks