rslc compiler.
E-QUANTUM
A type name has one precision. A type such asMoney = Num {precision: 0.01} gives its name one precision. This check guards a type name that two declarations give two different precisions.
A current rater gets an earlier message in its place. The compiler stops at the second declaration of a name with E-UNRESOLVED: duplicate Types declaration 'Money'. A guideline that declares Premium differently from the rater it uses gets E-USE.
Keep one declaration for each type name. Give a second precision its own name, such as WholeMoney = Num {precision: 1}.
E-ROUND
A rounding states its scale and mode.round takes three arguments: a value, a scale and a mode. The scale is a whole number of decimal places: 2 for cents, 0 for whole dollars, -1 for tens. The mode is one of half_up, half_down, half_even, up, down, ceiling and floor.
Filings differ on how they round a tie, so RSL leaves the mode for you to state. A rounding that states its rule gives the filed premium on every request, including one that lands on half a cent.
Example
The premium calls round with a value and a scale, and leaves out the mode.
half_up rounds a tie away from zero.
roundhas one argument, or more than three.- The scale is an increment such as
0.01; write the number of decimal places,2. - The scale lies outside -1000 to 1000.
- The mode is a name outside the seven modes, such as
nearest. round_each: (scale, mode)of a stepwisesumorproductbreaks one of the scale and mode rules above.interpolate!hasresult: exact; the result states a scale and a mode, and onlyratio:andstep:takeexact.interpolate!has a negativeratio:scale; a ratio lies between 0 and 1, so its scale is 0 or more.
Complete files
Complete files
bad/rater.rsl
good/rater.rsl
E-FOLD-KEY
A stepwise fold names its order. A stepwise fold rounds after every step:product(self.drivers as d by d.number, d.factor, round_each: (3, half_up)). It takes one element at a time and rounds the running result each time.
Rounding at every step makes the order of the elements matter. The by key fixes that order, so a request rates the same however it lists its drivers.
The check asks for by and round_each together, on a sum or a product. The key is a number or date input of the element, read as d.number. Each element of one list has its own key value, and the rater rejects a request that repeats one.
Example
The product rounds each step to three decimals and leaves out the by key.
by with the input that orders the elements, here the driver number.
- A fold has
byand lacksround_each; add the rounding, or deletebyfor an exact sum or product. byorround_eachsits on a fold other thansumandproduct, such asmax,avgorcount.- The key is a computed value such as
d.factor * 2, or an attribute of another record such asself.payroll. round_eachsits on asumof plain values, such assum(self.payroll, 1, round_each: (3, half_up)); a stepwise fold reads a list.rankhas abykey;rankorders by the list’s ownkeyed byfield.
Complete files
Complete files
bad/rater.rsl
good/rater.rsl
E-COMPUTED-RANGE
A calculation proves its declared range. A calculation states a promise about its value. A range readswhere self in [0, 100000], and a precision comes from a type such as Premium = Num {precision: 0.01}.
The compiler works out the range and precision of the body from the inputs it reads. The check asks the body to prove the promise for every request the rater accepts.
Calculations that read the value rely on the promise, for example as a divisor or a table key. A promise the body proves holds for every premium the rater returns.
Example
The premium declares a range up to 100,000. Payroll reaches 100,000,000 at a rate of 2 per 1,000, so the body reaches 200,000.
min(round(…), 100000). A filing that limits payroll calls for a narrower range on the input.
- The body reads an input with an open range such as
[0, _], so the body has an open bound on that side. - The calculation’s type has a precision and the body is off that grid, such as a
Premiumof whole dollars rounded to cents. Round the body to the declared scale:round(…, 0, half_up).
Complete files
Complete files
bad/rater.rsl
good/rater.rsl