catala icon indicating copy to clipboard operation
catala copied to clipboard

Syntax question: deconstructing tuples

Open AltGr opened this issue 1 year ago • 2 comments
trafficstars

We agreed to introduce tuples in the surface language (see #529). This is very straightforward, but we also need a way to destruct them to get back their members.

  • Currently I (locally) have let a, b, c equals some_triple in ... to get a, b and c as new variables pointing to the different elements of the triple.

    • This will feel very natural for functional programmers; but from what I have seen with beginners I think it's actually a pretty confusing way to write the thing. To be checked! :)
  • We will want that in patterns anyway match some_triple with pattern -- (a, b, c): .... I think the ordering makes this form clearer, but that will come with full-fledged patterns which is further down our TODO list

  • Patterns usually appear in other places, e.g. function arguments: declaration myfunc content integer depends on x, y, z content (integer, decimal, money) equals ... Then we get the issue of "function depending on 3 arguments" vs "function depending on a single argument which is a triple". I'd very much like to avoid that and unify the two to make the lives of the users simpler; so the above could be written instead with the multiple-argument syntax: ...depends on x content integer, y content decimal, z content money equals.... Then the function can be called in two ways, myfunc of x, y, z (current way), but also myfunc of some_triple if the types match.

  • This won't be liked by functional programmers, but it could be a mistake to overlook the very simple and straightforward syntax some_triple.1, some_triple.2, some_triple.3 to get to the different members.

AltGr avatar Dec 08 '23 14:12 AltGr

Decision of the syntax committee over #549 : full pattern matching syntax and .1, .2 syntax that desugars to full pattern matching, but no let (x, y) = z (too confusing).

denismerigoux avatar Jan 09 '24 16:01 denismerigoux

Status update:

  • foo.1, foo.2 etc. is now supported
  • the syntax let (x, y) = z is still supported and should probably be removed
  • no pattern-matching yet

AltGr avatar Jun 26 '24 08:06 AltGr