Then, a pattern (x, y) is bound to the tuple (x, y). When a pattern is bound, the variables in the pattern are given the corresponding values on the right hand side. So basically, x and y are bound to themselves, which is a no-op.
All that is obvious to me, and I used random so the compiler wouldn’t optimize everything away and I could look at the generated JS. But you completely glossed over 4 pairs of matching parens on the right side.
to me, destructuring like this
let (x,y) = (1,2)
makes sense, but something else is afoot when this works
Extra parentheses are no-ops in ReScript, just like they are in JavaScript. 1 is equal to (1), and equal to (((1))). The formatter removes the extra parentheses for this reason.
In the case of (1), the way it is parsed has nothing to do with tuples. It’s doing the same thing as JavaScript: grouping expressions together to control precedence. It’s why this 2 + 3 * 4 is different than this (2 + 3) * 4. Just like JavaScript, there’s nothing stopping you from adding extra parentheses around an expression, even if they’re superfluous.
It’s a syntax error because JavaScript can’t understand parentheses around a variable name on the left hand side. In ReScript it’s parsed and discarded. It has nothing to do with tuples. You can verify this by trying let x = (1) in ReScript. It has a type x : int. Just a simple int, no tuples.