Having watched Richard's talks on Roc and having read through the tutorial, I got the impression that Roc did not support tuples. After peeking in the Dict.roc implementation I was surprised to discover that they are a working feature in the language! I understand wanting to discourage the use of tuples when records serve all the same purposes while being necessarily more descriptive, just as using Bool
is discouraged when custom tag unions are much better at communicating intent. Given this, I'm curious as to why tuples exist in the language at all?
As a follow-up, the Roc repl seems to annotate tuples with an asterisk (e.g: (Nat, Nat)*
) just like growable records are. Does this imply tuples can accumulate fields as well? Or are tuples simply syntax sugar for records with unnamed fields?
Hi @Sven van Caem :)
I'm curious as to why tuples exist in the language at all?
This is the origin discussion for the current tuples.
As a follow-up, the Roc repl seems to annotate tuples with an asterisk (e.g:
(Nat, Nat)*
) just like growable records are. Does this imply tuples can accumulate fields as well? Or are tuples simply syntax sugar for records with unnamed fields?
@Ayaz Hafiz should know this one
Thanks for the link!
If I'm following along correctly, I'm getting that tuple types are extensible to allow for functions like .1 to work on tuples of length 2 or greater, and so forth
When I tried to get the type signatures of .0
, .1
, etc I got the following result:
» .0 : ( a )* -> a
» .1 : ( a )* -> a
» .2 : ( _, _, a )* -> a
» .3 : ( _, _, _, a )* -> a
Just looking at it, I'd expect .1
to have the type ( _, a )*
What am I missing here?
Probably a copy paste bug if I had to guess. Given the type is built into the compiler, it probably has special code for generating that signature.
I've filed issue #5676 for this.
Last updated: Jul 06 2025 at 12:14 UTC