rbs icon indicating copy to clipboard operation
rbs copied to clipboard

support * in tuples

Open HoneyryderChuck opened this issue 1 year ago • 3 comments

I've found that I can't type a certain type of code I maintain, where it'd make sense to do so.

operation = ["+"]
operation << 1
operation << 2

I'd like to type this as a tuple of a given type at the head, and variable values of same type at the tail, smth like operation: [String, *Integer], but the parser does not support that.

HoneyryderChuck avatar Apr 05 '24 21:04 HoneyryderChuck

I understand the motivation. The extension itself looks reasonable, but I'm afraid if further extension is required? Like [String, *Integer, Symbol] or [*Integer, String, *bool].

Do you think having one * types at the end of tuple makes enough sense?

soutaro avatar Apr 06 '24 01:04 soutaro

tuple_type ::= `[` _type_ `,` ... `,` _type_ `]`        # Closed tuple
             | `[` _type_` `,` ... `,` `*` _type_ `]`   # Open tuple

soutaro avatar Apr 06 '24 01:04 soutaro

I'd follow the ruby rule here, and only allow * at the end, and once. Allows for a simpler implementation perhaps, and you can always consider extensions later on based on demand.

HoneyryderChuck avatar Apr 06 '24 09:04 HoneyryderChuck