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

fromEither should be called fromRight to match Haskell and allow for fromLeft #642

Closed
futpib opened this issue Jul 11, 2019 · 6 comments
Closed

Comments

@futpib
Copy link
Contributor

futpib commented Jul 11, 2019

Eventually, we might want to have both fromLeft and fromRight:

fromLeft :: a -> Either a b -> a
fromRight :: b -> Either a b -> b

but right now we have fromEither :: b -> Either a b -> b which, if kept as it is, would result in this inconsistency:

fromLeft :: a -> Either a b -> a
fromEither :: b -> Either a b -> b

Also, fromEither is a good name for a different function:

fromEither :: Either a a -> a

This would also match names for these function in Haskell

@davidchambers
Copy link
Member

fromLeft and fromRight sound good to me, @futpib! The only problem with your proposal is that it would make the naming of S.fromMaybe internally inconsistent. For consistency, that function should be renamed fromJust, but Haskell uses that name for its impure Maybe a -> a function.

I see three options:

  1. Status quo (internally consistent; no a -> Either a b -> a function)
  2. Copy Haskell (internally inconsistent)
  3. Provide fromJust, fromLeft, and fromRight (internally consistent; inconsistent with Haskell)

Which option do you favour?

@futpib
Copy link
Contributor Author

futpib commented Jul 11, 2019

Do you think, if rename anything at all, we should choose once whether to use type or constructor names in these function?

If we choose to always use constructor names, maybeToNullable (justToNullable) will be an outlier, with no constructor for Nullable possible.

I think the best strategy is to use type names when no confusion is imaginable, otherwise use constructor names.

Under this rule, fromMaybe and maybeToNullable are fine since there is no value in Nothing (fromNothing, nothingToNullable make no sense).

I also noticed other similar inconsistencies, so I think Maybe-related functions should be left as is, but these Either function should be split into Left and Right pairs:

Old New
maybeToEither maybeToLeft
maybeToRight
fromEither fromLeft
fromRight
eitherToMaybe leftToMaybe
rightToMaybe

And fromEither should be added with the new meaning of

fromEither :: Either a a -> a

@davidchambers
Copy link
Member

I believe that this issue can be closed now that #683 has been merged. Do you agree, @futpib?

@futpib
Copy link
Contributor Author

futpib commented Aug 11, 2020

I disagree, these goals are not reached yet:

@davidchambers
Copy link
Member

@futpib, shall we close this issue and open a new one for the conversion functions, or would you prefer to update this issue's title and description?

@futpib
Copy link
Contributor Author

futpib commented Aug 16, 2020

Having #644 open is enough, I think

@futpib futpib closed this as completed Aug 16, 2020
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

No branches or pull requests

2 participants