Say I have some foo :: Maybe Int and I want to bind it for example with bar :: Int -> MaybeT (Writer String) Int, what would be the idiomatic way to do that?
I could define my own liftMaybe function, and then use that, like:
let liftMaybe = maybe (fail "Nothing") return in liftMaybe foo >>= bar
But is there a more idiomatic (or at least concise) way to do that?
I think it’s a shame it doesn’t have a standard name, however doing a hoogle search, we see that the
reludepackages useshoistMaybe:A more general form is
which is preferable to the use of
fail. I’d just put it in a convenient module somewhere.