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

Simplify instantiation of generic-bound union members #106

Open
domn1995 opened this issue Jan 7, 2023 · 1 comment
Open

Simplify instantiation of generic-bound union members #106

domn1995 opened this issue Jan 7, 2023 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@domn1995
Copy link
Owner

domn1995 commented Jan 7, 2023

Consider the following union:

[Union]
public partial record Option<T>
{
    public partial record Some(T Value);
    public partial record None;
}

Currently, to instantiate the Some variant, we must write the following:

var some = new Option<int>.Some(42);

Since the generic type parameter is bound to the union, we must define the type parameter every time since it cannot be inferred from the type passed to the union member. It would be nicer to be able to do the following:

// Inferred as `Option<int>.Some` since `42` is an integer.
var someInt = Option.Some(42);
// Inferred as `Option<string>.Some`.
var someStr = Option.Some("foo");
@domn1995
Copy link
Owner Author

domn1995 commented Jan 7, 2023

For backward compatibility, we probably want to expose this through a generated XPrelude static class where X is the union name. Ex:

using OptionPrelude;

var some = Option.Some(42);

@domn1995 domn1995 added help wanted Extra attention is needed good first issue Good for newcomers enhancement New feature or request and removed help wanted Extra attention is needed good first issue Good for newcomers labels Jan 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant