Added scopes test to see things more clearly

This commit is contained in:
Denis Merigoux 2020-06-11 15:58:54 +02:00
parent 2d60c4a4d5
commit 1d506e1594
2 changed files with 70 additions and 0 deletions

4
tests/scopes/Makefile Normal file
View File

@ -0,0 +1,4 @@
CATALA_LANG=en
SRC=scopes.catala
include ../Makefile.common

View File

@ -0,0 +1,66 @@
/*
declaration structure Child :
data date_of_birth content date
data age content integer
declaration scope ChildWellFormed :
context child content Child
scope ChildWellFormed :
definition age equals years of (now - date_of_birth)
declaration scope ChildBenefit :
context child content Child
context child_well_formed scope ChildWellFormed
scope ChildBenefit :
definition child_well_formed.date_of_birth equals |01/01/2000|
definition child equals child_well_formed.child
# To what is this translating to ?
# ChildWellFormed translates to
# (child.date_of_birth * child.age) -> (child.date_of_birth * child.age)
# So what will the implementation of ChildBenefit look like in the lambda calculus?
#
# let ChildWellFormed (
# child.date_of_birth, child.age, child.child_well_formed, child_well_formed.age
# ) =
# let child_well_formed.age = 12 in
# let (child_well_formed.date_of_birth, child_well_formed.age) = child_well_formed (
# child.child_well_formed, child_well_formed.age
# ) in
# let (child.date_of_birth, child.age) =
# (child_well_formed.date_of_birth, child_well_formed.age)
# in
# (child.date_of_birth, child.age)
# We can see that definitions in the caller scope can either :
# - set a parameter of the callee scope
# - retrieve a result of the caller scope
# In the caller scope, uses of callee scope variables should correspond
# to uses of the result of these variables after calling the scope, while
# callee scope variable definitions should correspond to callee scope parameter
# setting before the call.
# But setting a parameter of the callee scope can conflict with a definition of
# this parameter inside the callee scope.
scope ChildBenefit :
definition child_well_formed.age equals 12
# How do we resolve things now ? Do we have
# - child_well_formed.age = 12 or
# - child_well_formed.age = years of (now - child_well_formed.date_of_birth) ?
#
# Well the answer to this question lies in default logic! More precisely, we have
# to pick a precedence order between definitions of the caller scope and definitions
# of the caller scope. Because the law sometimes says things like :
#
# "compute this benefit like mentionned at article XXX but change the threshold
# Foo to $ZZZZZ."
#
# The meaningful semantics to give here is that caller scope definition should
# have higher precedence on callee scope definitions.
*/