Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Add fromAlt #90

wants to merge 5 commits into from

Conversation

Fresheyeball
Copy link

I find this function useful.

Copy link
Collaborator

@phadej phadej left a 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't fromAlt), 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).

@Fresheyeball
Copy link
Author

Mention optional :: Alternative f => f a -> f (Maybe) in the haddock

Can you explain why? I don't get it.

I'd like some different name (optional isn't fromAlt), but I don't know what it should be

What do you think about just alternative?

I'd like the x to be tried once; now

I don't understand this comment either.

@phadej
Copy link
Collaborator

phadej commented Jul 16, 2018

-- or 'alternative'
fromAlt :: f a -> f b -> Either a b
fromAlt x y = Left <$> x <|> Right <$> y

I'd like a name referring to These. But as said, it's my problem, if you have no better suggestion.

Third point, I cannot explain better.

fromAlt launchMissles (throw "oops")
   = These <$> launchMissiles <*> throw "oops"
       <|> That <$> throw "oops"
       <|> This <$> launchMissiles
   = ...
   = launchMissiles *> (This <$> launchMissiles)
   /= This <$> launchMissiles

@Fresheyeball
Copy link
Author

How about optionally? or maximize?

I still dont know what to day about optional in the haddocks, do you want to just edit the haddocks to say what you want?

I get your concern now about the order of operation. Will fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants