-
Notifications
You must be signed in to change notification settings - Fork 205
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
Records: Should records provide a unit type? #1301
Comments
If we make Not sure what
If you statically know that you have an empty argument list, you can write it much briefer than
The only benefit is to not have two unit types in the system (no |
This is what I had in mind. Basically every object is a unit tuple in terms of "does it support the operations unit tuples require". :) I didn't see the need to add another top-ish type to the Object, dynamic, void happy family.
Ah, this is an interesting point. I do care about uniformity and spreading potentially-empty argument lists, so this could be a problem. Let's sit on it for now until we know more about how argument spreading would look. |
I'm pretty skeptical that this works out well. I'd need to see a really detailed workup. Some concrete issues that come to mind:
Maybe this works out - I get the appeal, but... it makes me really, really nervous. |
Making I'd drop the Even without The next question is whether we need a zero element tuple type at all.
I'm not sure how probable those cases are, but they're not impossible, so ruling out zero-tuples isn't an obvious win. All in all, for consistency, it's probably a reasonable idea to have a zero-element tuple type and value (that value should probably also be canonicalized). Syntax might be tricky. Can we use |
The current proposal doesn't have a Destructure0 interface (since it wouldn't do anything). If we were to add one, then, I agree having
This is the more interesting one. I think we'll know more when argument spreading is better defined. I'm not opposed to adding a unit tuple if we think it helps. |
Good question. The fact that variable declarations don't always have a keyword means that the type annotation and expression grammars overlap in some syntactic positions. We'll have to make sure the record syntax avoids that collision. I'm still working on the pattern and variable declaration syntax, but I'll keep this in mind. I think keeping it unambiguous will be annoying but not intractable. |
The grammar uses position to recognize types. For As for using |
@tatumizer Same problem today var x = int?[0]; Is it So, |
Function types also bring some ambiguity when the return type isn't specified. e.g. |
@ds84182 We had to special-case the parser so that |
It looks like the empty tuple type would be nice to have for consistency, but the concrete reasons for having it now are not so obvious. In particular, it is tempting to think that argument lists and tuples can be considered as tightly connected, but it seems to come with some conflicts with static type safety. @leafpetersen wrote:
I think everyone agrees that the empty tuple type should not be So we'd need the empty tuple value (hence type). But the situation where an argument list has a shape which is not statically known mainly occurs in the body of If subtyping allows So tuples may look like they give us abstraction over different argument lists with type safety, but if it is not type safe then it doesn't buy us so much compared to the The question is then how helpful it would be to have So it comes down to the need for the value I think we need to decide on the desired connection between argument lists and tuples, and the desired level of static typing, and then the decision on the unit type may be strongly influenced by that decision. |
For the record, I seem to have filed this issue a second time here. I'm going to close this out in favor of the more recent issue. |
In this record proposal, the unit (empty) record is not sallowed. Should it be? It seems fragile to elide it, and likely not to compose well with meta-programming and other features. E.g.
If we provide a way to reify argument lists as tuples, what happens if you reify the empty argument list? Do you get
null
? IF so, the non-uniformity is likely to be painful.Same question for meta-programming - a macro which generates methods (e.g. copyWith) will be non-uniform in the zero field case in a way that will make the macro more complex.
Same question for "apply". If we provide a way to spread a tuple into an argument list, then does the empty argument list need to be special cased?
In general, it feels like disallowing the zero width case is likely to cause future pain with the non-uniformity. What is the benefit of eliding it?
The text was updated successfully, but these errors were encountered: