-
-
Notifications
You must be signed in to change notification settings - Fork 675
Inline/anonymous enum declaration #4338
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
This is an interestring idea. I also often use enums for function args only, so it would be handy to be able to define those right in the signature. |
Funny that Mortoray used to be a Haxe user back in the days ;) |
There's a macro for that: https://gist.github.com/back2dos/2785f42c5a52a7f2369a#file-usage-hx :P It's just a proof of concept, but if there is really value to this, it should get you started. Personally I find error messages with types that have no names really unintelligible. Introducing a type with a well chosen name is sometimes hard, but it's well worth the effort, as it makes code much more readable. |
Hmm, that macro is very cool, I didn't even think about that. BTW, I think we can loose the array decl and use |
Good point. Slightly related question: will that become |
@back2dos very cool :) |
Not very beautiful syntatically tho... (array decl, var keyword) |
Nice macro indeed ! |
@nadako: I'm not sure you could get rid of the array declaration, it's the only reliable way to enter expression-mode as far as I know. |
Yeah I understand that. It's just one of the reason that macros is not the ultimate answer for everything: here they bring redundant syntax that makes harder for a reader to understand that it's an enum declaration. IMO. |
I'm not sure about that. With Ideally we would have some special syntax for that (as well as |
\o/ |
I think it would be better to have a name there also, e.g. Also actually we could enable that for enums/abstracts for clarity (i.e. |
Lol, ignore my |
@nadako Yep, it's a bit quirky. It was either @ncannasse Correct. Although for that to actually work, all ComplexTypes need to be resolved to Types in the current context and then the signature has to be calculated based on those (because otherwise you may get collisions based on imports) and the generated enum needs to be built based on the Types (because it has it's own import context). And for that to fully work one also needs proper handling of type parameter handling, and so on, and so forth. While I'm really into expressive syntax, I don't see enough value in this to actually make a solid implementation. Names are powerful! @Simn: You made my day! |
I'm not sure what the status is here. The idea seems interesting for small cases, but is it practical beyond that? |
I don't think so. All this saves you is one identifier, that would name the enum (and typing There's a lot of approaches that I think would solve this as a side effect. Be it first class type unions, the type system being aware of string constants (as in TypeScript) or maybe symbols (as in Ruby or ES6). I think #4281 is somewhat relevant to this. It links to this rather intriguing proposal that made it into TypeScript: microsoft/TypeScript#1003 |
Alright then, let's close this for now. |
It would be handy to support anonymous enums in Haxe, similar to how anonymous types are supported.
Proposed syntax:
This was what got me thinking about it:
http://mortoray.com/2015/06/15/get-rid-of-those-boolean-function-parameters/
The text was updated successfully, but these errors were encountered: