Syntax question: deconstructing tuples
AltGr opened this issue · comments
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 geta
,b
andc
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 alsomyfunc 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.
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).