`fromEither` should be called `fromRight` to match Haskell and allow for `fromLeft`
futpib opened this issue · comments
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
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:
- Status quo (internally consistent; no
a -> Either a b -> a
function) - Copy Haskell (internally inconsistent)
- Provide
fromJust
,fromLeft
, andfromRight
(internally consistent; inconsistent with Haskell)
Which option do you favour?
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
I disagree, these goals are not reached yet:
- From issue description:
-
- Change the meaning of
fromEither
(#690)
- Change the meaning of
- From #642 (comment):
-
- Add
Either
↔Maybe
conversion functions (#644)
- Add
@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?