RFC-055: Operations Are Defined per Type

AcceptedNot implemented
Depends on

Context

Every input, output and parameter in a rulework declares a type (boolean, number, amount, string, date, array, object or decision), and an amount or number may carry a unit (RFC-023). Nothing in the law format says what an operation does with those types. The engine decides, one function at a time, and RFC-037’s checker rejects only some combinations, only where it knows the types. The result is behavior no author would predict from the YAML:

  • AND, OR, NOT, an IF condition and a FOREACH filter accept any value and treat 0, "" and empty lists and records as false, everything else as true.
  • ADD of a date and a string concatenates them as text, because a date is a string at run time.
  • DATE_ADD and DATE drop the fraction of a number: months: 1.5 adds one month.
  • EQUALS of two different types is false, except a date string against $referencedate, which is compared as a date.
  • IN does not compare the way EQUALS does: IN "2025-01-01" [$referencedate] is false where EQUALS on the same pair is true, and a value that is not a list is treated as a list of one.
  • DATE_PART and START_OF turn an unknown or absent date into a type error, where every other operation passes the unknown on or reports the absence (RFC-036).
  • eurocent × percentage is accepted as eurocent, a hundred times the amount the law means unless the author also divides by 100.
  • DIVIDE rounds its result to the roughly 28 digits the engine’s decimal library holds. The law never asked for that rounding, and it shows: FLOOR((1 ÷ 3) × 3) is 0, not 1.

Several of these were deliberate when introduced. The common cause is that the law format does not define what an operation does with its operands, so the engine’s code is the only definition. Another engine built to the same format could make different choices and still conform to it.

No existing type system covers money, units, the difference between an absent and an unknown value, and the decision type together; FEEL, Catala and CQL were surveyed, and Alternatives Considered says why none is adopted.

Decision

Every operation has a closed list of signatures: the operand types it accepts and the type it returns. Operands that match no signature are an error, found at load time where the checker knows the types and at run time where the value shows them (see Errors). Nothing is converted implicitly, except in the five cases listed under Types. A combination a law needs that the table lacks is added as a new row.

Types

The signatures use the schema’s types. In the arithmetic and comparison rows number includes amount; Amounts and units says which combinations are valid. A count an operation takes (a precision, the parts of a DATE, the components of a DATE_ADD) is never an amount.

  • Integer and decimal. A number is an integer or a decimal, by how it came about. A number written in a rulework or passed in is an integer when it has no fraction, so 5 and 5.0 both are. ADD, SUBTRACT, MULTIPLY, MIN and MAX give an integer when every operand is one. DIVIDE and PERCENTAGE_OF always give a decimal, so 10 ÷ 2 is a decimal 5. ROUND, CEIL and FLOOR give an integer when the result has no fraction, and the date operations give integers.
  • Whole number. Where a signature asks for a whole number, any number without a fraction qualifies, integer or decimal; 2.5 is an error, never truncated.
  • Equality. Two numbers are equal by value: the integer 5 equals the decimal 10 ÷ 2. Inside an array or object, an integer against a decimal of the same value is an error instead, wherever in the structure it sits, as decided for comparing a new decision with a recorded one (Awb 7:11). Arrays of different length, objects with different fields and elements of different types are unequal, not an error.
  • Fields. $a.b reads the field b of the object $a. On a null it gives null, on an unknown it gives unknown, and on an untranslatable it gives untranslatable. A field the object does not have, and a path into a value that is not an object, are errors.

The five conversions the format does make:

  1. Date literals. A string literal in the form YYYY-MM-DD is a date wherever a date is required: as an operand, in the array of an IN whose subject is a date, and as the value or an IF outcome of an output declared date. A definition holds a literal too: a bare one in that form is a date where one is required, and a structured one may declare type: date. A literal in that form that is no calendar day, such as 2025-02-30, is an error. A value that enters through a field declared date is parsed when it enters. The result of an operation is never converted: an ADD of strings stays a string.
  2. $referencedate, an object with fields iso, year, month and day, is accepted wherever a date is, and its field iso is a date.
  3. Undeclared values. A value whose type the checker does not know (a field of a record, a FOREACH element, an array item) is read as a date where a signature requires one, when it is a string in that form; otherwise it is an error. That covers the date operations and an ordering, EQUALS or IN with a date on the other side, so AGE with date_of_birth: $kind.geboortedatum works. An ordering of two such values compares them as dates. A field declared string stays a string.
  4. A FOREACH over a value that is not an array iterates once over that value, as RFC-016 and the schema define.
  5. Plain numbers. A plain number beside a number in unit u is read in u. One given as the percentage of PERCENTAGE_OF, or as a component of DATE_ADD, is read in that unit. Beside an amount it is read as eurocents only in a comparison, in IN, as an IF outcome, and where it meets a declared output or parameter. In adding and subtracting only the literal 0 is: a zero written in the operation itself, 0 or 0.0. A definition that holds zero is a plain number.

Absent, unknown and untranslatable

null (absent), unknown and untranslatable are not types. An operation evaluates its operands in the order written, all of them unless its notes say it stops early, and an error in one of them ends it. Then it looks at what it got, in this order (RFC-031, RFC-036):

  1. An untranslatable operand makes the result untranslatable.
  2. Otherwise an unknown operand makes the result unknown.
  3. Otherwise a null operand is an error, except where RFC-036 and RFC-037 allow it; the notes below say where.
  4. Only then are the types held against the signatures.

So ADD of an unknown value and a string is unknown at run time, while the checker reports the string at load. Every operation follows this order, DATE_PART and START_OF included. AND, OR, IN, IF and a FOREACH with combine: AND or OR do not look at all their operands, and LIST, RECORD and a FOREACH without combine keep a null or unknown element; their notes say how.

Signatures

T is any type, the same within a row. … means one operand or more; none is an error, except for AND and OR. The date and comparison rows follow FEEL, the rules for money follow Catala, and the rest follow earlier RFCs of this project.

Arithmetic

OperationOperandsResult
ADDnumber…number
ADDstring…string
ADDarray…array
SUBTRACTnumber…number
MULTIPLYnumber…number
DIVIDEnumber…number
MIN, MAXnumber…number
ROUND, CEIL, FLOORa number and a precisionnumber
PERCENTAGE_OFa number as percentage, a number as ofthe type of of
  • ADD of strings or arrays joins them in order.
  • SUBTRACT and DIVIDE take the first operand and subtract or divide by the rest. Dividing by zero is an error.
  • ROUND rounds to the nearest, a tie away from zero (-2.5 gives -3); CEIL rounds toward +∞ and FLOOR toward −∞ (RFC-024). precision is the number of decimals kept: a whole number from −28 to 28, the range of the released schemas, written in the YAML and not computed. A negative precision rounds to tens or hundreds, so -2 rounds an amount to whole euros.
  • PERCENTAGE_OF divides by 100; see Amounts and units.

Comparison

OperationOperandsResult
EQUALST, Tboolean
EQUALST, nullboolean
orderingnumber, numberboolean
orderingdate, dateboolean
  • The orderings are GREATER_THAN, LESS_THAN, GREATER_THAN_OR_EQUAL and LESS_THAN_OR_EQUAL. An earlier date is less than a later one (RFC-021).
  • EQUALS of two different types is an error, not false. It compares arrays and objects element by element. With null on either side, written or computed, it tests for absence: two absences are equal, and an absence and a value are not (RFC-036).

Logic

OperationOperandsResult
AND, ORboolean…boolean
NOTbooleanboolean
IFboolean conditions, T outcomesT
  • AND and OR evaluate their conditions in the order written. A null condition is an error when it is reached. A condition that settles the answer, a false in AND or a true in OR, ends the evaluation with that answer (RFC-036). When no condition settles it, an untranslatable one makes the result untranslatable, and failing that an unknown one makes it unknown. Without conditions AND is true and OR is false.
  • Conditions after the one that settles the answer are not evaluated, so the data they read is not fetched (RFC-043): putting the most decisive condition first reads less about a person.
  • An IF tries its cases in the order written and gives the then of the first case whose when is true, or the default when none is; without a default it then gives null (RFC-037). Only that outcome is evaluated: later conditions and the other outcomes are not, so the data they read is not fetched. A when that is unknown or untranslatable makes the IF unknown or untranslatable when no case before it was true, and the cases after it are not tried. The outcomes have one type, and an outcome may be null when the IF gives the value of a nullable output (RFC-037, rule N2).
  • The filter of a FOREACH is a boolean condition as well.

Collections

OperationOperandsResult
LISTany valuesarray
RECORDnamed valuesobject
INa T and an array of Tboolean
FOREACHan arrayarray, or see combine
  • LIST keeps every item as an element, a null, an unknown and an untranslatable one included.
  • RECORD gives an object with a field for each name in fields. It keeps a null or unknown value in its field, and an untranslatable value makes the whole record untranslatable.
  • IN is true when an element EQUALS the subject. The array is given as values or as value, never both; a value that is not an array is an error, and a null array gives false. Elements are checked in order up to the first match, so later ones are not evaluated. A match wins over an unknown or untranslatable element, as a true does in OR; without a match, an untranslatable element makes the result untranslatable, and failing that an unknown one makes it unknown. An element of another type than the subject, other than null, is an error when it is reached. A null subject matches a null element.
  • A FOREACH over null iterates nothing. Without combine it gives the array of its results, null and unknown ones included. An element whose filter is unknown is kept as an unknown element, and a null filter is an error.

FOREACH reduces its results with combine:

combineElementsResultNo results
ADDnumbernumber0
ANDbooleanbooleantrue
ORbooleanbooleanfalse
MIN, MAXnumbernumbernull
ONLYTTnull
DISTINCTTarray of Tan empty array
  • ONLY gives its one element as it is; more than one element is an error.
  • DISTINCT gives the elements that differ, in the order each first occurs. Two elements are the same when EQUALS says so, and a null element is kept once.
  • combine: AND and OR follow the operations of that name: an element that settles the answer wins over unknown and untranslatable ones, and the iteration stops there, so the data of later elements is not fetched. An element whose filter or body is unknown or untranslatable counts as such an element.
  • For ADD, MIN, MAX, ONLY and DISTINCT, and without combine, an untranslatable element makes the whole result untranslatable (RFC-016). An unknown element makes the result of ADD, MIN, MAX and DISTINCT unknown, and a null element is an error for ADD, MIN and MAX.

Dates

OperationOperandsResult
DATEthree whole numbersdate
DATE_ADDa date and whole numbersdate
DATE_DIFFtwo dates and a unitnumber in that unit
AGEtwo datesnumber in years
DATE_PARTa date and a partplain number
DAY_OF_WEEKa dateplain number
START_OFa date and a partdate
  • A date is a day of the Gregorian calendar in the years 0001 to 9999, without a time or a time zone.
  • DATE takes a year, a month and a day, each a plain whole number. A date that does not exist, such as month 13 or 30 February, is an error.
  • DATE_ADD adds years, months, weeks and days, in that order. Each is optional and a whole number, which may be negative. After the years, and again after the months, a day past the end of the month becomes its last day: 31 January plus one month is 28 or 29 February, and 29 February 2024 plus one year and one month is 28 March 2025.
  • DATE_DIFF counts complete days, months or years from from to to. A month is complete on the same day of a later month, or on the last day of a shorter month: 31 January to 28 February is one month (RFC-021). A year is complete on the same date, and for 29 February on 28 February in a common year. When to is earlier than from, the result is the negative of the count the other way round.
  • AGE is DATE_DIFF in years from date_of_birth to reference_date, so it is negative before birth.
  • DATE_PART reads the year, month or day; START_OF goes back to the first day of the year or month; DAY_OF_WEEK gives 0 for Monday up to 6 for Sunday.

Decisions. A decision (RFC-045) is read through its fields, passed on, called anew through source.article, and compared with EQUALS. It may be an outcome of an IF, an element of a LIST or of the array of an IN, and the element a FOREACH with ONLY gives. Every other operation on a decision as a whole is an error.

Amounts and units

An amount is money, counted in the minor unit of its currency. This RFC knows one currency, the euro, so an amount counts eurocents. It is any exact number and may have decimals, as a rate of 29.43 cents does; a field that holds whole cents says so with precision: 0. An amount the law states in euros is written times 100. Showing euros is a matter for the screen: a frontend divides by 100 when it displays an amount, and multiplies by 100 when someone enters one. A data source that delivers euros is converted when its value enters, never inside a rulework. “Rounded to whole euros” is ROUND with precision: -2.

An amount is a type of its own and declares no unit: the units euro and eurocent are removed. Every field declares a type and a unit is optional, so as a unit money would be checked only where someone remembered to write it. Two units for one quantity have also produced wrong answers: with the Awir in euro and the zorgtoeslag in eurocent, one person on one income came out at €827.63 or €1,550.46 depending on which convention won, and nothing warned.

Units are for numbers that are not money. A number may declare one in type_spec.unit, on a field or on a definition; a unit on a field that is not a number is refused. RFC-023’s rule stays: a plain number is never refused for its unit.

UnitMeasuresExample
years, months, weeks, daysa duration6 months
ratioa share, where 1 is the whole0.05 for 5 percent
percentagea share, in hundredths5 for 5 percent

No unit converts into another: years and months are different units, as are ratio and percentage. Those two are scales for one thing: 143 percent of the minimum wage is a ratio of 1.43 or a percentage of 143. Neither has a range, and adding or comparing one with the other is an error, which is what keeps 0.05 and 5 apart. A ratio above 10 written in a rulework, in a definition or as a literal, is probably a percentage (13.7 as a ratio would be 1370 percent), and the checker warns about it without refusing the rulework. It cannot catch a small one: 1.896 reads as 189.6 percent.

Kinds. Every number has a kind: amount, one unit, or plain. A plain number is a literal such as 100, a count, or a field nobody annotated. The kind of an expression follows from its declaration or from the tables below and from nothing else, so two checkers find the same. A number the checker has no declaration for (a field of a record, a FOREACH element, an array item, a DATE_DIFF whose in is computed) has no known kind. It fits every row, and the result has the kind the other operands give, if any; unlike a plain number, it passes beside an amount in an ADD.

Adding and subtracting. ADD, SUBTRACT, MIN, MAX and the elements of a combine take operands of one kind:

OperandsResult
amount and amountamount
amount and the literal 0amount
u and uu
u and plainu; the plain number is read in u
plain and plainplain
anything elseerror

A plain number is not read as money here, because a count or a rate added to an amount is a mistake that should not pass. A definition that holds money declares type: amount, and in MAX [$bedrag, 5000] the 5000 belongs in such a definition. The literal 0 is the exception, because zero is zero in every currency: MAX [0, $bedrag] sets a floor at zero, and SUBTRACT [0, $bedrag] negates an amount. A number with a unit does take a plain number beside it (RFC-023): the Leerplichtwet counts school days by adding weekday numbers to a difference in days. Here u is any one unit, so 1 − $fractie is a ratio, and days + months, ratio + percentage and amount + days are errors.

Comparing and choosing. The orderings, EQUALS, IN and the outcomes of an IF follow the rows for adding, with one more: a plain number beside an amount is accepted and read as eurocents. GREATER_THAN $inkomen 2500000 with $inkomen an amount compares with €25,000, and an IF that gives an amount may write a literal outcome: default: 0 is an amount of zero.

Multiplying. The operands may come in either order:

×amountdurationratiopercentageplain
amounterroramountamounterroramount
durationamounterrordurationerrorduration
ratioamountdurationratiopercentageplain
percentageerrorerrorpercentageerrorpercentage
plainamountdurationplainpercentageplain

“Duration” in a result is the unit of the operand: months × ratio is months. A ratio leaves the kind to the other operand, so half of a plain 10 is a plain 5, and only ratio × ratio is a ratio. An amount times a duration is an amount, as a daily amount times a number of days. One MULTIPLY or DIVIDE pairs an amount with at most one duration: amount × days × days is an error in any order, as is amount ÷ months ÷ months.

Dividing. The row is the dividend, the column the divisor:

÷amountdurationratiopercentageplain
amountplainamountamounterroramount
durationerrorplain, the same unit onlydurationerrorduration
ratioerrorerrorplainerrorplain
percentageerrorerrorpercentageplainpercentage
plainerrorerrorplainerrorplain

amount ÷ amount is a plain number: how many times the one fits in the other, or the share the one is of the other. An output that stores it as a share declares the unit ratio. months ÷ months is plain too, and years ÷ months is an error. 12 ÷ amount would be “per eurocent”, which has no type or unit here, and is an error.

A percentage of an amount is the operation PERCENTAGE_OF, not a multiplication:

operation: PERCENTAGE_OF percentage: $tarief # 21 for 21 percent of: $bedrag

Its percentage is a number in the unit percentage or a plain number. An amount, a duration or a ratio there is an error: a ratio of 0.21 means 21 percent, and would be read as 0.21 percent. Its of is a number of any kind, and the result has that kind: 21 percent of an amount of 10000 is an amount of 2100. The engine divides by 100, and the operation’s name says so in the YAML, which keeps RFC-023’s rule that a label never changes a value. MULTIPLY of an amount and a percentage stays an error, so a hand-written product cannot silently come out a hundred times too large. That protects only a number declared percentage, so a number that holds a percentage declares that unit, or is stored as a ratio.

Rounding and dates. ROUND, CEIL and FLOOR keep the kind. AGE gives years, and DATE_DIFF the unit it counts in when in is written as a literal. DATE_PART and DAY_OF_WEEK give a plain number. The years, months, weeks and days of DATE_ADD each take a plain number or a number in that unit: months: $termijn with $termijn in weeks is an error.

No compound units. There is no type for “euro per day” or “per eurocent”. A rate is an amount with decimals: 29.43 cents per kWh times a consumption of 2900 is an amount of 85347. What an amount is per is not recorded, so a monthly amount times a number of days passes; see the open question on amounts per unit.

Where a value meets a declaration. Wherever a value crosses a declared field, it has that field’s type and its kind is checked. The checker reports a mismatch at load where it knows the type or kind of the value, and the engine at run time for what the value shows.

FieldRule
outputThe value has the declared type; RFC-037’s rule T4 said so for a literal, and it now holds for every value. An amount output takes an amount or a plain number, and an output in unit u a number in u or a plain number. An output whose value has a unit the checker knows declares that unit: leeftijd = AGE … declares unit: years. A value in another unit, or an amount in a number output, is an error.
input that reads another law’s outputHas that output’s type, where amount and number are different types, and the same unit when both declare one.
parameter passed to another lawChecked as an output is: an amount parameter takes an amount or a plain number.
open termThe implementing output and the term’s default have the type the term declares. In v0.9.0 the term may declare type_spec; its unit is then compared as for an input, and without one units are not compared.
finding, projection stateHas the type of the open term it decides, or of the state property. Checked as a caller’s parameter is; both may declare type_spec in v0.9.0.
overrideHas the type of the output it replaces, and the same unit when both declare one.
input or parameter filled by a caller or a data sourceChecked on entry for what the value shows (a number, a string, a date) and for its precision. Whether a number is an amount or carries a unit cannot be read from the value, so it takes the kind its declaration gives.

A hook produces ordinary outputs, and a row read from recorded decisions or facts is a record whose fields have no declaration. A field is checked when a value crosses it: an input when it is first read and an output when it is computed, since a value that is never read is never resolved (RFC-043). Across laws the checks follow RFC-037’s load order, and loading a rulework re-checks the loaded ruleworks that read its outputs, implement its open terms or override its outputs.

Precision

Numbers are exact. No operation rounds except ROUND, CEIL and FLOOR, so every rounding in a calculation is one the law prescribes (RFC-024): (1 ÷ 3) × 3 is 1.

  • Entry. A number written in a rulework or passed by a caller means its decimal notation exactly: 0.1 is one tenth, not the nearest binary float. A number that arrives as a double, as from JavaScript, is read as the shortest decimal that gives that double.
  • Declared precision. A value with more decimals than its field’s type_spec.precision is an error, on every output, intermediate ones included, and on inputs and parameters: output toeslag declares precision 0 and received 83.33…. The rulework then rounds where the legal text says how; the check refuses where another design would round, as DAML’s RoundingUnnecessary does. The checker reports it at load where the expression already shows that the value can have more decimals than declared: precision: 0 on a division, or on a product with the rate 0.3693, with no ROUND, CEIL or FLOOR after it. A precision per element of an array or record waits for typed records. type_spec.min and max stay metadata.
  • Answers. Every value may be a fraction, an output a caller asks for included, so X ÷ 12 × 12 is X and nothing is rounded in between. An output that declares no precision makes no claim about its decimals, and an answer such as one third is written as the Exit point below says. The checker warns at load about an output that ends in a division with no rounding after it, because its legal text usually prescribes one.
  • Exit. The engine writes values in two forms, and both stay. The stored form, for what is kept and read back such as stage state and recorded decisions, is exact, and gains a notation for a fraction. The ordinary form, for the API, the WASM build and traces, writes a number through a float, as it does today, so a fraction shown along the way appears as its nearest double, as a long decimal already does. RFC-039 leaves the fix for that serialization to an RFC of its own.
  • Size. Fractions with different denominators grow when they are added: 1/3
    • 1/7 + 1/11 + 1/13 is 1934/3003, and a FOREACH that divides each element by a different number can reach thousands of digits. A number whose numerator or denominator exceeds a limit is an error that names the operation where it happened. The limit is a resource limit the implementation sets, like those on collection size and nesting depth, and not a rule of the format: raising it changes no outcome, only whether an answer arrives. In practice the error points at a rulework that misses a rounding its legal text prescribes, or at a data source that delivers absurd precision.

Errors

Operand types that match no row are rule T6 of the checker, and kinds that match no row, in an operation or at a declaration, are rule U1. The checker reports them at load, in just validate and when a rulework is loaded, wherever it knows the types and kinds, and stays silent where it does not. T6 replaces RFC-037’s rules T1 to T3, T4 now covers every value, and T5 (calling an article’s decision, in the checker since RFC-045) stays. Rule P1 is a declared precision that the expression of its output cannot keep. Two rules warn without refusing the rulework: U2 for a ratio above 10, and P2 for an output that ends in a division with no rounding after it. just validate prints a warning, the editor shows it, and the enrichment pipeline gets it as a finding.

The engine refuses at run time what a value shows: whether it is a boolean, a number, a string, a date, an array or an object, for every operation it executes. Whether a number is an amount or carries a unit, and whether an object is a decision, follows from declarations, so only the checker enforces it. A branch of an AND or an IF that is never executed is checked only by the checker too.

Every way an operation can fail has a name. UnsupportedOperation names the operation and the operand types, as in ADD is not defined for (date, string), and UnitMismatch the kinds, whether an amount or a unit is involved, as in months and days do not add.

  • UnsupportedOperation: operand types that match no row. Found at load (T6) and at run time.
  • UnitMismatch: kinds that match no row. Found at load (U1).
  • TypeMismatch: a value of another type than its field declares, or a path into a value that is not an object. Found at load (T4) and at run time.
  • AbsentOperand, NullForNonNullable, NullOutput: a null where none is accepted. Found at load (RFC-037) and at run time.
  • DivisionByZero: division by zero. Found at run time.
  • InvalidOperation: a fraction where a whole number is required, ONLY with more than one element, IN with both or neither of value and values, or no operands. Found at run time, and at load where it is written out.
  • InvalidDate: a date that does not exist, or a string that is no date where one is required. Found at load for a literal, otherwise at run time.
  • PrecisionExceeded: more decimals than a declared precision. Found at load (P1) where the expression shows it, otherwise at run time.
  • ArithmeticOverflow: a number over the size limit. Found at run time.
  • VariableNotFound: a field the object does not have. Found at run time.

UnsupportedOperation and PrecisionExceeded are new; the engine has the others today.

Older schema versions

The rules of this RFC hold for every rulework the engine loads, whatever schema version it names. An operation has one meaning, so a rulework on an older version that relies on behavior this RFC ends is refused when it is loaded, with the finding that says why. A schema version decides only which notation is read:

  • Schema v0.9.0 drops the units euro and eurocent; released versions keep them, because they are frozen. From an older version, eurocent on an amount is accepted and ignored, eurocent on a number is read as an amount, and euro is refused with a message that names the fix: an amount, the value times 100.
  • Schema versions up to v0.4.0 had the operations NOT_EQUALS, NOT_NULL, NOT_IN and SWITCH, and the engine also reads IS_NULL. They are read as their current form: NOT_EQUALS as NOT of EQUALS, IS_NULL as EQUALS with null, NOT_NULL as NOT of that, NOT_IN as NOT of IN, and SWITCH as IF. An engine that does not read those versions need not know them.

Extending the table

The table is closed so that additions are deliberate, not to keep it small. A row is added in a pull request that names this RFC and adds a test for the row in the engine, the checker and the conformance suite (bdd/). A row that converts between types, rounds implicitly or introduces a type needs its own RFC.

Why

Benefits

  • The format answers the question. What ADD does with a date is written down, so a second engine is conformant or it is not.
  • Mistakes surface where they are made. A FOREACH filter that returns a count instead of a verdict is reported, where today it filters on non-zero.
  • One table for checker and engine. RFC-037 names “two type systems” as a tradeoff. Read from one table, they agree on every operation.
  • A known design. Checking statically where a type is known and at run time otherwise is gradual typing (Siek and Taha, 2006).

Tradeoffs

  • Ruleworks that run today will fail where they rely on behavior this RFC ends, most likely truthiness over property paths and IN over a non-array value. The rules hold for every schema version, so a rulework kept outside this repository is refused by the engine release that carries this RFC until it is fixed. Migration lists what the corpora meet.
  • Declared precision starts to count. The demo corpus carries 174 precision declarations in type_spec, most of them amounts with no decimals; corpus/regulation and corpus-poc carry none. An output that now receives an unrounded value behind such a declaration fails until the rulework rounds it where its legal text prescribes, or drops the declaration.
  • Strictness costs convenience. IN 5 ["5", 6] was a harmless false; now the author has to make the list consistent.
  • A percentage is checked only when it is declared. A whole percentage stored as a plain number (21) passes MULTIPLY with an amount and gives a result a hundred times too large; the Participatiewet’s verlaging_percentage is such a number, divided by 100 by hand. This is the argument this RFC uses against money as a unit, and it holds here too: no field in the corpus declares percentage today.
  • Values without a declaration are checked only for what they show. A field of a record, a FOREACH element and an array item have no declared kind, so amount, units and decision are not checked for them: $kind.toeslag × $regeling.percentage passes as two numbers. In the corpus that is about 4 percent of the operands of arithmetic.

Alternatives Considered

Adopt FEEL. FEEL (DMN) has the most complete operator tables of the surveyed systems and a Rust implementation (dsntk). It has no money or units, and its null flows through arithmetic, which RFC-036 forbids for an absence. RFC-011 already chose against DMN as the rules language.

Adopt CQL’s quantities. HL7 CQL, a language for clinical rules, has quantities with UCUM units, calendar durations and three-valued logic. It has no money, and an operation that fails returns null where this format raises an error.

Adopt Catala’s types. Catala’s money and date rules are the closest to what a law needs. It rounds money to the cent automatically, where RFC-024 rounds only where the law says so, and it keeps whole and decimal numbers apart, where the corpus treats them as one number. There is no Rust runtime.

A fixed working precision. IEEE 754 decimal128 fixes 34 digits and rounds ties to even, and FEEL means its numbers to behave that way. It would make the format, not the library, decide the last digit, and it keeps numbers bounded. It is still a rounding the law did not prescribe, and FLOOR after a division can still land on the wrong side of a whole number. Catala uses exact fractions for the same reason. A fixed number of decimals per field, as SQL’s DECIMAL has, needs a rule per operation for the decimals of the result, and SQL itself leaves that rule for division to each database.

Money as a unit on number. Money could be number with the unit eurocent, with amount removed, which puts every quantity in one model. A money field without its unit would then drop out of every money rule, and 94 of the 656 amount fields that can declare a unit declare none today. A type is required on every field, so amount is always checked.

Document today’s behavior. That makes the engine predictable without breaking a rulework, but it puts “a non-empty string is true” into the law format, which no legal text means.

Complete the checker and leave the engine alone. The checker cannot see property paths, FOREACH bindings or array elements, and values also reach the engine from callers and data sources. The engine has to refuse what a value shows by itself.

Deviations from earlier RFCs

Where this RFC changes what an earlier one lays down:

  • RFC-003. An open term may declare type_spec.
  • RFC-012 and RFC-031. An untranslatable operand made every result untranslatable. In AND, OR, IN and combine: AND and OR, an operand that settles the answer now wins. For AND, OR and IN the engine already does this; RFC-036 states it for an unknown only.
  • RFC-016. combine: ADD joined strings and arrays, and combine: AND and OR took any value as true or false. ADD now takes numbers, and AND and OR take booleans, follow the operations of that name and stop at the element that settles the answer.
  • RFC-021. Dates stayed strings at run time, IN stayed structural, and EQUALS fell back to comparing strings when a side was no canonical date. A date is now a type of its own, IN compares as EQUALS does, and a string against a date is an error.
  • RFC-023. The units euro and eurocent go, money being the type amount. An output declares a unit its value is known to have. The unit algebra RFC-023 left to the engine is laid down here, with two changes to what the engine does: two numbers in one unit divide into a plain number and not a ratio, and a percentage no longer multiplies an amount or a duration. Its “(0-1)” for a ratio names a scale, not a range.
  • RFC-024. A tie on a negative number goes away from zero, which RFC-024 left open, and type_spec.precision is checked.
  • RFC-037. T6 replaces T1 to T3, T4 covers every value and not only a literal, date and string are no longer one type (a string becomes a date only through conversions 1 and 3), and units are checked at load.
  • RFC-045 and RFC-046. An amount in a finding may have decimals, and the stored form gains a notation for a fraction.

When this RFC is accepted, each of these RFCs gets a note that RFC-055 amends it. RFC-023 keeps its status.

Implementation Notes

  • One table. The signatures and the kind rules live in one module of the engine crate, read by typecheck.rs for T6 and U1 and by operations.rs before each operation. U1 replaces the unit pass that runs with every action today and the static pass in just validate. A reference page in the docs is rendered from the table.
  • A date value. To refuse ADD of a date and a string at run time, the engine must tell a date from a string. Value gains a Date variant, parsed at the boundary and written back as YYYY-MM-DD, so traces, the WASM API and stored values keep their form.
  • Exact numbers. rust_decimal gives way to an arbitrary-precision rational type (num-rational or malachite). Parsing reads a numeral from its text, not through f64. The stored form (stored.rs) gets a notation for a fraction beside __decimal. The trace format stays at version 1: a step for an amount keeps reporting unit: eurocent, so a screen still recognizes money.
  • Schema v0.9.0 adds PERCENTAGE_OF and drops the two money units. A definition gets a shape (value, type, type_spec), so a misspelled key or unit is refused where it is silently ignored today. A unit on an amount, or on a field that is not a number, is refused. Open terms and projection state may declare type_spec.
  • Parameters. The model drops a parameter’s type_spec today. It keeps it, on every schema version, so the unit and precision of a parameter are checked; 10 of the 174 precision declarations sit on parameters.
  • Amounts. The frontends decide on type: amount alone; the editor today also requires the unit and enters a unit-less amount as is, where the demo shows it as euros. The engine accepts only a whole number for an amount in a finding and in projection state today; both follow the declared precision instead.
  • Around the engine. The trace step of PERCENTAGE_OF shows the percentage, the amount and the result. RegelRijm (RFC-054) needs a form for PERCENTAGE_OF, since its build fails on an operation without one; it reads money from type: amount and no longer lends a unit to a plain operand of ADD, SUBTRACT, MIN and MAX. The law-generate skill and the enrichment checks stop prescribing unit: eurocent and a formula that divides by 100, and prescribe type: amount alone and PERCENTAGE_OF. Their wording for a ratio, and the editor’s label “Ratio (0-1)”, become “where 1 is the whole”. The conformance manifest (RFC-014) lists PERCENTAGE_OF in a level, and the pipeline’s check on units across laws is covered by U1.

Migration

This RFC changes rules under which today’s ruleworks are correct, so implementing it includes bringing the corpora along. It lands as schema v0.9.0, a breaking version after v0.8.22. A rulework stays on its schema version and moves to v0.9.0 when it needs something that version adds; no rulework in the corpora uses euro, or eurocent on a number. Ruleworks kept outside this repository need the same fixes before they load on the engine release that carries this RFC; just validate of that release lists the findings.

What the corpora meet, counted in November 2026 in corpus/regulation, corpus/demo and corpus-poc:

ChangeRegulationDemoPoCHow
unit: eurocent on an amount56124382none: accepted and ignored; dropped when the rulework moves to v0.9.0
additions that mix an amount with money in a definition without type: amount2460by hand: the definition gets type: amount
outputs whose value has a known unit but declare none616script, the unit follows from AGE or DATE_DIFF
outputs ending in a division without rounding31229by hand for the 10 that declare a precision; the rest get the warning P2
MAX or MIN with the literal 022138none, allowed by the rule for zero
truthiness, IN over a non-array, EQUALS across typescounted by step 1, fixed by hand

corpus-poc is outside just validate, but its proofs of concept run on the engine, so it moves along.

  1. Implement T6, U1 and the precision checks in a mode that reports instead of refusing, and run it over all three corpora.
  2. Apply the script for the mechanical rows. Fix every other finding in the rulework, or add the row the law turns out to need.
  3. Switch from reporting to refusing in the change that lands the fixes and schema v0.9.0.

RFC-037’s zero-findings test stays and covers T6 and U1; because the fixes land with the switch, it stays green. RFC-037 narrows a rule that fires on a correct rulework, because such a finding is a bug in the checker. Here the rules themselves change by decision of this RFC, so the corpus moves instead of the rule.

Open Questions

  • Conversion between units. The rules give no direct way to turn a percentage into a ratio, or years into months: multiplying by a plain 12 keeps the unit years, and an output in months then refuses it. Roundabout ways exist: PERCENTAGE_OF with of: 1 gives a plain 0.21, which an output in ratio accepts, and dividing by a definition of 1 in years gives a plain number. A conversion operation for the exact factors (percentage to ratio, years to months, weeks to days) would say it directly.
  • Other currencies. A rulework from a country outside the euro, or a Dutch version from before 2002 in guilders, needs another currency. It would belong to the rulework version, with the minor unit taken from ISO 4217: two decimals for the euro, none for the yen. Amounts in different currencies never combine, an input that reads an amount in another currency is an error, and conversion is an explicit step at a rate the law gives.
  • Fractions and percentages as types. Money is a type because a type is required and a unit is not. The same argument would make percentage, and then ratio, types of their own, leaving units only for durations. How often enriched ruleworks hold whole percentages should decide it.
  • Amounts per unit. A rate modeled as a plain amount loses what it is per: a price per kWh can be added to a total, a price per MWh taken for one per kWh, and a monthly amount multiplied by a number of days. An amount with type_spec.per (per: kWh, per: days) would keep it, and measured quantities would need units of their own, for which UCUM has standard codes. Such calculations are rare in the corpus, so the plain-amount rule is enough until one needs more.
  • An integer against a decimal in a list or record. That error dates from when the chronicle lost decimals on their way to disk, and was kept after that was fixed, so that the two are never silently equated. With exact numbers and exact storage the loss it guarded against cannot occur. Whether the rule still earns its place, with the integer and decimal rules it needs, is a question for those who decided it.
  • Dates in MIN and MAX. “The later of two dates” is a common legal construction; it is left out until a law needs it.
  • A non-array FOREACH collection. Iterating it once hides a data source that delivered one record where the rulework declares a list. Making it an error moves that fix to the data source.

Out of scope, each for a separate RFC: typed records and arrays, which would let the checker see the fields of an object and the items of an array, and a data source or caller be checked against them where a record comes in; and an option for DATE_ADD to refuse a day past the end of the month.

References

RegelRecht

An exploration into transparent, executable legislation, and one of the three projects in the starting selection of the Nederlandse Digitale Dienst.

Links

GitHub repository
How it works
Demo walkthrough
Stay informed
Roadmap (Dutch)
Documentation
Research
Basiswerk recht (Dutch)

Contact

regelrecht@minbzk.nl

Part of

Nederlandse Digitale Dienst
Ministry of Economic Affairs and Climate Policy