CatalaLang / catala

Programming language for literate programming law specification
https://catala-lang.org
Apache License 2.0
1.97k stars 78 forks source link

More overloaded operators #366

Open AltGr opened 1 year ago

AltGr commented 1 year ago

Following #365 it would be nice to do a little bit more:

Equality handling

For now equality is fully polymorphic and the backend or runtime is expected to provide a suitable implementation (recursive traversals in the interpreter, OCaml's infamous polymorphic equality in the OCaml backend, type classes in Python).

It would provide more guarantees and help with lower-level backends to have a more systematic way of handling it: have equality as an overload. That implies adding e.g. Eq_str of StructName.t to the resolved operators, and assuming generation of these specific operators for every type by the various backends.

:heavy_check_mark: More operators

The conversion operators like IntToRat and MoneyToRat could actually be overloaded on their input type, as a single to_decimal operator. This should be pretty straight-forward. Same for rounding operators.

Sum over a collection

For these constructions, we need not only the operator for adding the correct type, which we already have, but also the neutral element for said operation to use as initial value. Because of this, at the moment it's not possible to compute a sum without expliciting the type.

AltGr commented 2 weeks ago

NOTE: #671 has a (pretty dumb) implementation of equality tests instanciation in [lcalc/expand_op.ml], useful for the C backend as a placeholder. But it'll need to be replaced by something better, either an ad-hoc solution within the backend for inline code, or as part of monomorphisation.