-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
enum class like in Rust #2787
Comments
I may be wrong, but the languages that support it doesn't support union types as Crystal do. The functionality seems to overlap, only with different syntax. Do you have an user case where using this kind of enums would be significantly better than simply creating records/classes for each element and using them? |
Also: abstract struct Op; end
record Inc < Op, val : Int32
record Move < Op, val : Int32
record Loop < Op, loop : Array(Op)
record Print < Op That's what you traditionally do in OOP languages. That has the benefit that you can use What we do need is a way to have |
i used it here: kostya/benchmarks@a4f403f and it give 20% performance, comparing to symbols |
@asterite #285 is the issue you refer to. But is useful as long as you do not need to reopen each of those types. There you need to know what is the macro doing and is a leak of abstraction. The fact that they are different types allow us to use method & cases to match the constructor. But it lacks of proper pattern matching. If we reach proper pattern matching then it might have more sense definitely. Even so, the question is if it is a good idiom for crystal when used just as a bunch of records. I don't know if in the compiler itself would be useful. But it seems like a nice helper to have IMO. |
@kostya The performance improvement is probably because before the change you switched over the symbol, and then you used |
i tried with two fields also |
i think this nice feature to add, i think about this macro:
which expanded to:
but if it would possible that Op be resulted type, not Op::T (thats nicer)?
The text was updated successfully, but these errors were encountered: