roc icon indicating copy to clipboard operation
roc copied to clipboard

Desugar tuples to records

Open rtfeldman opened this issue 3 years ago • 2 comments

This is part of the SIMD proposal, and comes after https://github.com/rtfeldman/roc/issues/2932 and https://github.com/rtfeldman/roc/issues/2934

Tuples should desugar to numbered record fields; e.g. (a, b) should desugar to { 0: a, 1: b }.

This should presumably be done at the type-checking stage so that we can record that something originated as a tuple, allowing us to pretty-print errors using tuple syntax instead of record syntax even after the desugaring has happened.

rtfeldman avatar Apr 24 '22 03:04 rtfeldman

Is the desugared version meant to be usable outside of transforming tuples? Meaning, is the following valid Roc?

rec = { a: "hello", 4: 5 }

If the above is valid, we hit a problem destructuring. From the above example

{ 5 } = rec

Here, 5 would be a variable reference & a number literal.

jaredramirez avatar Jun 07 '22 01:06 jaredramirez

Yeah, the first code snippet should be valid Roc!

{ 5 } = rec should be a new compile error (probably checked during canonicalization) which is that you can't destructure numbered record fields.

rtfeldman avatar Jun 07 '22 01:06 rtfeldman

Closing as I think this is completed.

lukewilliamboswell avatar May 01 '24 08:05 lukewilliamboswell