Conversation
There was a problem hiding this comment.
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 (
optionalisn'tfromAlt), but I don't know what it should be - I'd like the
xto 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 <$> yI'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.