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

Either -> Result #22

Open
janekx21 opened this issue Aug 30, 2023 · 5 comments
Open

Either -> Result #22

janekx21 opened this issue Aug 30, 2023 · 5 comments

Comments

@janekx21
Copy link

Either is the wrong name for this monad, because Either = Left l | Right r sound symmetrical. But Either is not symmetrical, because its mapping and bind only works on the Right r constructor. The proper name should be Result = Ok value | Err error. This is not symmetrical and easier to read.

Elm Reference: https://package.elm-lang.org/packages/elm/core/latest/Result

@apfohl
Copy link
Contributor

apfohl commented Sep 3, 2023

To some degree you are right. But they are two different things when it comes to semantics. Result<T,TError> is basically a specialized variant of the Either<TLeft,TRight> monad, with the intention of getting an actual result in the success case and an error object in the case of failure.

Either<TLeft,TRight> can be used for this application as well, because it obviously has two sides. But it lacks the semantics. Mapping and binding works for both sides. If you see the ‚right‘ side as the correct one (as the name implies) you have the methods Map and Bind like in Maybe. For ‚left‘ you have MapLeft and MapRight. So it‘s fully usable for both cases. You would have a similar set of methods for a Result<T,TError> implementation.

Speaking of Result<T,TError>, I was planning this monad basically as the next addition to this library. If you wish, we can share knowledge and implement it. There is also another similar/same monad called ‚Exceptional‘.

hope this helps a little bit, with the understanding, why we only have Either<TLeft,TRight> at the moment. And thanks the the thoughts.

@apfohl
Copy link
Contributor

apfohl commented Dec 22, 2023

@janekx21 We discussed this topic and considering a rewrite of the Either monad into Result. We will keep the Either monad as obsolete in the library to maintain backwards compatability.

@Dirk-Peters-BF
Copy link
Contributor

The whole package will most likely be obsolete with the next dotnet LTS version, because actual discriminated unions, including built in Option and Result types, will be added.

@apfohl
Copy link
Contributor

apfohl commented Aug 13, 2024

Is it already in the next LTS? You have a link? Only saw the proposal. But yes. It’s a good thing that this is obsolete soon.

@Dirk-Peters-BF
Copy link
Contributor

correction: "maybe obsolete with the next dotnet LTS"
IMHO the proposal for typed unions looks already quite settled

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

3 participants