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

Implicit conversions #28

Closed
domn1995 opened this issue Jun 27, 2022 · 2 comments
Closed

Implicit conversions #28

domn1995 opened this issue Jun 27, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@domn1995
Copy link
Owner

domn1995 commented Jun 27, 2022

As a dunet user, I want some unions to support assigning its members' inner values directly, so that my code is more terse and less noisy.

For example, we should be able to do this:

using Result = Result<System.Exception, string>;

// No `new Result.Err()` required here.
Result exception = new Exception("Boom!");
// No `new Result.Ok()` required here.
Result success = "Success!";
// Compiler error.
Result invalid = 1;

[Union]
public partial record Result<TError, TSuccess>
{
    partial record Ok(TSuccess Value);
    partial record Err(TError Error);
}
@domn1995 domn1995 changed the title Implicit operators Implicit conversions Jun 27, 2022
@domn1995
Copy link
Owner Author

This feature probably doesn't make sense for all union types. What is the best way to determine when the implicit conversions should be generated?

@domn1995
Copy link
Owner Author

domn1995 commented Jun 28, 2022

This feature probably doesn't make sense for all union types. What is the best way to determine when the implicit conversions should be generated?

Here's some thoughts:

Restrictions

Union members may have implicit conversions if and only if the member has a single parameter (generic or not).

Feature Opt-in?

Should users opt into this feature or should all union members matching the above criteria get implicit conversions?

Nullability

How does null fit into this?

@domn1995 domn1995 added the enhancement New feature or request label Jun 30, 2022
@domn1995 domn1995 mentioned this issue Jul 6, 2022
@domn1995 domn1995 pinned this issue Jul 8, 2022
@domn1995 domn1995 unpinned this issue Nov 3, 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
Projects
None yet
Development

No branches or pull requests

1 participant