Funicular-Switch
Funicular-Switch copied to clipboard
Proposal: Add intermediate monadic types for option and generated results e.g. OptionNone with implicite conversion to Option<T> to enhance type inference
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<T> 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;
Hi, could you provide an example, where this type would help?
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>());