catala icon indicating copy to clipboard operation
catala copied to clipboard

Better use of bindlib: pretty-printing context

Open denismerigoux opened this issue 3 years ago • 1 comments
trafficstars

Upgrade to 6.0.0

This is a no-op; the breaking changes don't break anything in our codebase. The dune-project file should be modified though.

Better variable name printing

Right now, in the ~~Scopelang, Dcalc, Lcalc and~~ Scalc printers, as well as in the Python and OCaml backends, things are not done properly to ensure variable scoping and naming matches.

In the OCaml backend, we use Bindlib.name_of and rely on the invariant that the scoping rules of Lcalc match with those of OCaml. For other backends, we use Bindlib.hash to get the unique id for each variable, that we use to suffix all variables, at the price of horrible variable names.

This is a known problem though and Bindlib itself has a solution for it: https://lepigre.fr/ocaml-bindlib/6.0.0/bindlib/Bindlib/index.html#working-in-a-context-and-variable-printing. We should refactor the code of all these backends to make use of this feature and get nice variable names that respect the scoping rules in all the backends!

denismerigoux avatar Mar 28 '22 13:03 denismerigoux

When we rewrite variable naming in the backends to ensure clashes are prevented, there will be one more thing to take into account: now that we have modules, their contents need to be exported into reproducible and predictable names.

So all exported names shall be minimally rewritten, in a canonical way.

AltGr avatar Feb 22 '24 15:02 AltGr