Closed futpib closed 4 years ago
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:
a -> Either a b -> a
function)fromJust
, fromLeft
, and fromRight
(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 believe that this issue can be closed now that #683 has been merged. Do you agree, @futpib?
I disagree, these goals are not reached yet:
fromEither
(#690) Either
↔ Maybe
conversion functions (#644)@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?
Having #644 open is enough, I think
Eventually, we might want to have both
fromLeft
andfromRight
:but right now we have
fromEither :: b -> Either a b -> b
which, if kept as it is, would result in this inconsistency:Also,
fromEither
is a good name for a different function:This would also match names for these function in Haskell