haskell-issues icon indicating copy to clipboard operation
haskell-issues copied to clipboard

transformers: add hoistMaybe and hoistEither

Open neongreen opened this issue 8 years ago • 5 comments

hoistMaybe :: Monad m => Maybe a -> MaybeT m a
hoistEither :: Monad m => Either e a -> ExceptT e m a 

neongreen avatar Mar 19 '16 22:03 neongreen

Also consider adding isJustT and isNothingT.

neongreen avatar Mar 19 '16 22:03 neongreen

Alternatively, we could have liftMaybe :: Alternative f => Maybe a -> f a.

neongreen avatar Mar 19 '16 22:03 neongreen

liftMaybe = maybe empty pure isJustT/isNothingT proliferate boolean blindness and ought not to be needed in modern code - post an example where you would use it, and I'll see about solving it without bools?

Gurkenglas avatar Mar 20 '16 15:03 Gurkenglas

I only mentioned isJustT and isNothingT because I saw them in errors, but presently I don't have any use for them. As for liftMaybe, sure, the definition is simple, but it's been reinvented a few times by now so I feel that it could find a place in e.g. Data.Maybe.

neongreen avatar Mar 20 '16 15:03 neongreen

In that same vein:

fromMaybeT :: Monad m => m a -> MaybeT m a -> m a

(fromMaybeT = flip (<!|>))

Gurkenglas avatar Mar 26 '16 12:03 Gurkenglas