-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New extra combinator: generalised 'readMaybe' #161
Comments
@josephcsible Thanks for the suggestion! I can see how more polymorphic I think that both -- Either
rightZ :: (MonadPlus m) => Either e a -> m a
hush :: Alternative m => Either e a -> m a
liftEither :: MonadError e m => Either e a -> m a
eitherToError :: MonadError e m => Either e a -> m a
-- Maybe
hoistMaybe :: MonadPlus m => Maybe a -> m a
maybeToAlternative :: Alternative f => Maybe a -> f a
note :: MonadError e m => e -> Maybe a -> m a These functions come from popular and common packages like |
In However, such combinator still can be added to some |
To clarify, I definitely don't want a new function called |
readMaybe
is implemented like this:There's a lot of other types that it would be useful to generalize this to. Here's two ideas I've had:
Both of those are the same as
readMaybe
whenf ~ Maybe
. The first is useful for custom error monads to preserve whether the problem was "no parse" or "ambiguous parse". The second is useful forMaybeT
and lots of other things that have some sort of failure state.The text was updated successfully, but these errors were encountered: