-
Notifications
You must be signed in to change notification settings - Fork 214
[Enum] generic, constraint, types and named parameters for ADT Enums #2006
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
Comments
Duplicate of #349. |
enum Foo {
Bar, // 0
Baz = 123, // 123
Quux, // 124
} |
I think this can be closed now that the enhanced-enums proposal is being worked on. Issue #158 is the official tracking issue for the topic. |
I think this is very verbose and unnecessary, I've never seen it anywhere. The variations I know are Haskell's https://github.com/vlang/v/blob/master/doc/docs.md#sum-types |
I don't quite understand your concern. Looking at your examples, you seem to be asking for a way to give enums parameters and fields, like regular classes. I see that some of your examples don't take any arguments, or have a different signature than the other elements of the enum, but that's a smaller detail. The enhanced-enums proposal gives you the ability to treat enums like regular classes. Combine that with the idea of enum-like classes and you should be fine. Your first example would be something like: /// Enum-like class -- works today.
class Option<T> {
final int? value;
const Option([this.value]);
static const none = Option();
static const functor = Option<int>(4);
}
/// Enhanced enum -- requires the enhanced-enum feature.
enum Option<T> {
none(),
functor<int>(4);
final T value?
const Option([this.value]);
} |
I'm going to close this out because there are already existing feature requires for sum types, pattern matching, and members inside enum types. In the future, if you have a language feature request, please write a detailed explanation for what problem you would like the language to solve and how you think it should solve it. Copy/pasting snippets of code from other languages does not tell us very much. |
Dart enums are anemics and force us to use class
Dart Proposal
Rust Enums
The text was updated successfully, but these errors were encountered: