-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specify date rounding mode in scope declaration #293
Comments
@denismerigoux do you have strong opinions on what should be done regarding |
I think we can scrap |
There seem to be a shift/reduce conflict if I try to add something starting by |
Ah yes indeed. So two solutions.
|
I personally slightly prefer 1) since for me the date rounding is more a declaration than a definition thing. With 2) you would need a check for duplicate rounding mode definitions anyway. |
Thanks, I'll try 1) then. |
About the possible localisation issue, it might be worth thinking about it in a more general perspective: it's not pushed yet, but while updating the parser error messages I had a similar issue. I found it's often very helpful to print examples of the expected syntax, but at the moment those are in English only, with no easy way to "internationalise" them |
@AltGr I'm not sure I understand which localisation issue you're mentioning. |
Ah, sorry, that was lacking context! I meant localisation in the sense of internationalisation, i.e. being able to work with different natural languages (this is generally only concerned with translations of the program output, but in Catala we do have internationalisation of the input) |
The problem
Until now, Catala uses the calendar OCaml library for its dates computations. However, the level of precision offered by this library is insufficient to handle the ambiguities of dates arithmetic in the Gregorian calendar. For instance : what is
March 31 st + 1 month
? Is isMay 1st
orApril 30th
?To give a precise semantics to this kind of dates conundrum, we've developped our own dates computation library : https://github.com/CatalaLang/dates-calc. This library aims to offer a correctness-focused, minimal backend for Catala's dates computation that can be ported in other languages.
During the development of the library, it quickly appeared that date arithmetic is not exact and has to incorporate a kind of rounding for it to work. For instance,
March 31 st + 1 month
is rounded upMay 1st
and rounded downApril 30th
. By default, ambiguous computations that need rounding yield a runtime exception. But the law might set different meta-rule for dates computation. So, we needa way to specify the preferred rounding modes of dates in Catala.
Proposed solution
The naïve solution would be to set the dates rounding mode via an imperative flag, or a CLI option globally for the whole program. However, this is not functional enough for us, and might pose problem when two programs modelling two different portions of the law interact while having two different date rounding conventions.
So what we propose, is to attach the date rounding mode as a declaration belonging to a scope. All operations on dates that belong to this scope will inherit the declared date rounding mode. Here's a proposal for the syntax:
This syntax reuses part of the
MetaAssertion
surface syntax that's currently unsused and should be cleaned/refactored.The text was updated successfully, but these errors were encountered: