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

Proposal: Add intermediate monadic types for option and generated results e.g. OptionNone with implicite conversion to Option<T> to enhance type inference #38

Open
Tyrrx opened this issue Mar 25, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@Tyrrx
Copy link
Member

Tyrrx commented Mar 25, 2024

C# has very limited type inference. An intermediate monadic type representation would support C#'s type inference. For instance returning a OptionNone from Option.None that will be implicitly converted to an Option as soon as it is passed to an already strong typed method. This could be just an extension as Option.None<T> could still return Option<T>.

// struct Option<T>: 
public static implicit operator Option<T>(OptionNone value) =>
            Option<T>.None;
@Tyrrx Tyrrx added the enhancement New feature or request label Mar 25, 2024
@ax0l0tl
Copy link
Member

ax0l0tl commented Apr 18, 2024

Hi, could you provide an example, where this type would help?

@Tyrrx
Copy link
Member Author

Tyrrx commented Apr 19, 2024

Easiest example would be:

Option<int> opt = Option.Some(0);
Option<int> maybeOne = opt.Bind(one => one == 1 ? Option.Some(one) : Option.None);
// vs
Option<int> maybeOne = opt.Bind(one => one == 1 ? Option.Some(one) : Option.None<int>());

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

No branches or pull requests

2 participants