Open msprotz opened 3 years ago
I only now stumbled upon this old issue, but similar questions keep arising regularly.
At the risk of stating the obvious, inlining or lazy evaluation come to mind, although in a restricted setting. But the actual implementation triggered another idea: what if we were to remove the ErrorOnEmpty
guarding all (non-output) variables, and move them to the positions where the variables are being used ? Semantics wise, that will probably be more difficult to express (additional wrapping, or another kind of exceptions ?) but it might be worth exploring.
Based on a long discussion with @denismerigoux. Here's a Catala example:
The only output that I care about is the value of
foo
. However, if I call this scope withparagraph_b_applies = true
, then I get a fatal error because the definition ofbar
is empty, even though I do not needbar
for computing my outputfoo
.The reason is that this gets translated to:
and the evaluation of
bar
is unconditionalIf, however, I were able to annotate
foo
with an attribute that says "this is an output of my top-level scope", then the program above would contain more opportunities for rewriting; for instance, a simple syntactic analysis could uncover thatbar
is only needed in the first computation, and the program could be rewritten as such:This would provide a superior user experience; rather than providing an un-needed default case for
bar
whenparagraph_b_applies
(which legally does not make sense), we ensure instead that the compiler "figures out" thatbar
is needed only for the computation offoo
under conditionparagraph_a_applies
and rewrite the default calculus term accordingly.Questions to work out: