catala
catala copied to clipboard
Sugar for operations on collection literals
Operations on collections are purposefully a bit verbose, with e.g. minimum always requiring or if collection empty then <expr>;
This is good to enforce being careful against this kind of errors, but during pair-programming sessions I found that the Law in a few occurences had a computation of a minimum of a fixed set of values. So for now we use a binary min_money function that we defined, and apply it in a tree:
min_money of
quantity_A,
min_money of
quantity_B,
quantity_C
etc. It works but I was thinking of using the nicer and more readable syntax for collections:
minimum of [
quantity_A;
quantity_B;
quantity_C;
] or if collection empty then $0
This also benefits from the overload of the operator (although we could arguably add built-in, overloaded operators for binary min and max).
The or if collection empty stance here, however, is obviously useless and quite unpleasant;
that sugar would need to be implemented at the parser level, since this is where that syntax is enforced.