Stream: beginners

Topic: Tuples' place in Roc


view this post on Zulip Sven van Caem (Jul 10 2023 at 18:39):

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?

view this post on Zulip Sven van Caem (Jul 10 2023 at 18:42):

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?

view this post on Zulip Anton (Jul 11 2023 at 10:14):

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.

view this post on Zulip Anton (Jul 11 2023 at 10:23):

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

view this post on Zulip Sven van Caem (Jul 17 2023 at 16:17):

Thanks for the link!

view this post on Zulip Sven van Caem (Jul 17 2023 at 16:18):

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

view this post on Zulip Sven van Caem (Jul 17 2023 at 16:20):

When I tried to get the type signatures of .0, .1, etc I got the following result:

view this post on Zulip Sven van Caem (Jul 17 2023 at 16:20):

» .0 : ( a )* -> a

» .1 : ( a )* -> a

» .2 : ( _, _, a )* -> a

» .3 : ( _, _, _, a )* -> a

view this post on Zulip Sven van Caem (Jul 17 2023 at 16:21):

Just looking at it, I'd expect .1 to have the type ( _, a )*

view this post on Zulip Sven van Caem (Jul 17 2023 at 16:23):

What am I missing here?

view this post on Zulip Brendan Hansknecht (Jul 17 2023 at 18:47):

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.

view this post on Zulip Anton (Jul 18 2023 at 08:32):

I've filed issue #5676 for this.


Last updated: Jul 06 2025 at 12:14 UTC