Richard Feldman said:
that obviously looks like a mistake, plus it suggests that
(foo, bar,)should be valid as well for a 2-tuple
Are optional trailing commas not expected to be allowed in Roc? That's probably my least-favourite thing about JSON.
If you do allow trailing commas in dynamically sized collections like arrays, it would seem to be an odd special case to forbid them in tuples, structs, or other comma-seperated syntax.
And if you allow 2-tuples, 3-tuples, 4-tuples, etc I would argue it a very odd special case to disallow 1-tuples (or even 0-tuples, being similar to or the same as an empty record).
oh actually we do allow trailing commas, although I don't think I've ever seen them used in single-line tuples like that :sweat_smile:
Andy Ferris said:
If you do allow trailing commas in dynamically sized collections like arrays, it would seem to be an odd special case to forbid them in tuples, structs, or other comma-seperated syntax.
And if you allow 2-tuples, 3-tuples, 4-tuples, etc I would argue it a very odd special case to disallow 1-tuples (or even 0-tuples, being similar to or the same as an empty record).
this is an interesting point...I'd never thought of it that way!
In roc, the rest of the syntax makes a 1 tuple or 0 tuple unnatural. They are just parens for precedence.
So they don't just fall out of the syntax
yeah certainly calling (foo) a 1-tuple would be weird
but it's a fair point that:
[foo, bar,] is valid syntax...[foo,] be?[foo,] is valid syntax, and (foo, bar,) is valid syntax, then why wouldn't (foo,) be?(foo,) is valid syntax, then what else could it possibly mean besides a 1-tuple?I'm not saying we should embrace it, but that is a coherent argument for 1-tuples "falling out of" trailing commas in collection literals
8 messages were moved here from #ideas > custom types by Richard Feldman.
currently the formatter removes trailing commas in single-line types
so if we did want to support 1-tuples, we'd have to have the formatter keep them in
and (foo,) definitely still looks like a mistake to me :stuck_out_tongue:
and then I guess you'd destructure it with like (x,) = onetuple
which also looks like a mistake
a consistency argument against the idea of 1-tuples is that in every other collection literal, trailing commas are optional; they can be omitted without changing the meaning of the literal
and in the case of a 1-tuple that would not be the case, since (foo) is not a tuple at all
so there's a consistency counterargument too
I guess the only value of one tuples is working with a function that accepts any tuple and only calls .0 on it?
Like a function that only interacts with the first arg of a tuple.
I don't think there is any other tangible gain in roc from it
that and making wrapper custom types more concisely than using a single-field custom record
which doesn't seem like a big advantage to me :big_smile:
One feature of the zig formatter is, that if you set a trailing comma, it puts every element on its own line. And if you remove the trailing comma, it removes the newlines and puts all elements in the same line.
I like this feature. Maybe this is something you could think about adding to the Roc formatter.
But this feature would be strange for single tuples, if they need a trailing comma. It would be strange if you could online define a single tuples with multiple lines.
I do agree that (foo,) looks strange. It still looks strange to me! Yet I have found its presence elsewhere useful.
To me it's just the natural fallout of using ( ... ) brackets for two distinct purposes: as parentheses/expression grouping and as tuples. Given that design decision, using (foo,) as a one-tuple and (foo) as parentheses around foo is just a consequence of that initial design, nothing more or less. It's the syntax tradeoff that eventually rears its head because you took advantage of round brackets for two separate things.
That zig formatter rule seems pretty cool, though arguably multiline tuples are a bit of a code smell, so one could use it for arrays but not tuples for example, or disable it for all single-element collections, etc.
Last updated: Jun 16 2026 at 16:19 UTC