-
Notifications
You must be signed in to change notification settings - Fork 49
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
Add fromAlt
#90
base: master
Are you sure you want to change the base?
Add fromAlt
#90
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good function to have. Few comments:
- Mention
optional :: Alternative f => f a -> f (Maybe)
in the haddock - I'd like some different name (
optional
isn'tfromAlt
), but I don't know what it should be - I'd like the
x
to be tried once; now
fromAlt launchMissles (throw "oops")
will launch missiles twice. (Or more practically, e.g. in parsers you'd confuse error reporting. You might get "expected x, or y, or x" diagnostic).
Can you explain why? I don't get it.
What do you think about just
I don't understand this comment either. |
-- or 'alternative'
fromAlt :: f a -> f b -> Either a b
fromAlt x y = Left <$> x <|> Right <$> y I'd like a name referring to Third point, I cannot explain better. fromAlt launchMissles (throw "oops")
= These <$> launchMissiles <*> throw "oops"
<|> That <$> throw "oops"
<|> This <$> launchMissiles
= ...
= launchMissiles *> (This <$> launchMissiles)
/= This <$> launchMissiles |
How about I still dont know what to day about I get your concern now about the order of operation. Will fix. |
I find this function useful.