FStar icon indicating copy to clipboard operation
FStar copied to clipboard

Overloaded `&`: make non-dependent tuple whenever possible

Open W95Psp opened this issue 2 years ago • 2 comments

Hi,

Recently in a Slack conversation about deprecating the * operator for tuples in favor of the overloaded & operator, @TWal pointed out that the & operator sometimes makes dependent tuples when it is not necessary. Quoting him:

TWal: I sometimes had legitimate use of *, for example for the pair x:a{p x} & b, F* makes it a dependent pair so the fix I found was to write x:a{p x} * b

This PR makes the & operator desugar to a non-dependent tuple whenever it is possible. It only desugars to dependent tuples if there is actually a dependency.

W95Psp avatar Feb 01 '23 00:02 W95Psp

We chatted about some options today:

  • Taking this patch, which can be a breaking change
  • Using a different symbol for non-dependent and dependent tuples (& and&>?)
  • Having the user write tuple2/dtuple2 (one of the two) to disambiguate, and keep & for the other.
  • Desugaring to dtuple2 and displaying a warning when the variable does not appear in the right type.
  • Desugaring this to dtuple2, and enclosing the left type in parentheses to make it a tuple2, (so x:a{p x} & b is dependent, but (x:a{p x}) & b is not). I tried it here and here and regressions seem minor.

mtzguido avatar Feb 14 '23 23:02 mtzguido

Personally I'm in favor of the last point you're mentionning Guido. It's a purely syntactic thing, the rule is easy to understand and I think it is quite intuitive. I think we should close this PR in favor of that parenthesis rule change

W95Psp avatar Feb 15 '23 06:02 W95Psp

I ended up implementing the parenthesis option in #3317. Closing. Thanks Lucas and Théophile for bringing up the issue!

mtzguido avatar Jun 17 '24 20:06 mtzguido