rslc 0.8.0, included with the matching Relativities release. Use RSL 0.4.2 when your plan needs verification or underwriting. Use the RSL 0.5 authoring preview to try module and function syntax for supported raters.
The first two examples return the entered amount as written premium, up to $100. Each example uses a separate folder for checking and packaging.
Write the rating rule
Save this file aslegacy/rater.rsl. The rsl field in spec selects the edition. RatingOutcomes names the result.
legacy/rater.rsl
preview/rater.rsl. The first line selects RSL 0.5. The module names the entry function, and show names the result. The sample uses the same cent grid and input range as the first file.
preview/rater.rsl
Check and export both files
profile in each report. RSL 0.4 uses verify. RSL 0.5 uses preview, which checks the supported authoring forms and reports errors in the source. If you change Money to an undefined type in the preview file, the check fails with E-UNRESOLVED and points at the type name. Fix the error before exporting.
rslc fmt FILE for canonical formatting.
Group related inputs in a record
A required field can hold another record. Declarecoverage: Coverage in Policy, declare the scalar rating fields in Coverage, and read them through that field, for example policy.coverage.amount. The exported input schema describes a nested JSON object. If the amount is out of range, the refusal names Policy.coverage.amount.
Declare coverage: Coverage? if the request can omit the object. The schema
allows either the object or null. Omitting the field or sending null selects
the none arm. When a request supplies an object, its fields follow the
Coverage declaration, and the some arm can read them.
optional-record/rater.rsl
Calculate a value on an optional child
Afor block over an optional child declares a calculation on the
child. Read the calculation in the some arm of a match. The none arm
handles a missing or null child.
Save the example as optional-child-calculation/rater.rsl.
optional-child-calculation/rater.rsl
Accept several records in one field
A plainList(Exposure) keeps the same input shape in both editions. Save this RSL 0.4.2 example as legacy-list/rater.rsl. The record and its inputs are declared under Records.
legacy-list/rater.rsl
preview-list/rater.rsl. The item type and the containing record are declared at module scope.
preview-list/rater.rsl
{"Policy":{"amount":10,"exposures":[{"amount":5.25},{"amount":12}]}} to supply two items. An empty array, a missing exposures field, and "exposures": null all supply an empty list. Each item is validated independently. For example, an amount over 100 in the second item is refused at Policy.exposures[1].amount.
Require a bounded list
Putcount in [1, 3] inside the list declaration to require at least one item and admit up to three. Save this example as bounded-list/rater.rsl and use an RSL 0.5 preview build that supports list counts.
bounded-list/rater.rsl
exposures field supplies zero items, as does an empty array. Each fails the minimum with INPUT-LEN at Policy.exposures. Four items fail the maximum at the same path. The published input schema marks exposures required and lists the limits as minItems and maxItems.
Rate a keyed list and break a tie
Usekey number to require a unique number for each exposure in the list. Calculate each exposure’s charge in a for block, add the rounded charges with sum, and use argmax to select the exposure with the highest charge. The tie key clause selects the lowest number when charges are equal.
Save this example as keyed-list/rater.rsl and use an RSL 0.5 preview build that supports keyed records and selectors.
keyed-list/rater.rsl
lead_number is 10 even though that exposure comes second. When the list is empty, sum returns zero and argmax returns none. The example returns lead_number as 0 in that case. Reusing number 20 for the second item returns INPUT-KEY at Policy.exposures[1].number.
Select a matching record from a keyed list
Usefind(item.eligible for item in policy.items) to get the first eligible item by ascending declared key. A match returns some item. A list with no match returns none. The query stops at the first match, so later rows do not have to calculate the predicate. Use record Item key number when the input uses the submitted item number as its key.
Group arithmetic with a fallback
RSL 0.5 requires parentheses whenotherwise and arithmetic meet at the same level. For amount otherwise base + fee, rslc reports E-FALLBACK-GROUPING and suggests both ways to group it.
With amount otherwise (base + fee), the fee applies only when amount is absent. With (amount otherwise base) + fee, the fee applies to either amount. Save this example as optional/rater.rsl.
optional/rater.rsl
amount takes the fallback of 7. An explicit zero stays zero. The nonoptional fee defaults to 1 when omitted or null. An explicit zero overrides the default.
Read a list of enum values
A field declared aschoices: List(Choice) takes a JSON array such as
["alpha", "beta"] when Choice declares those enum members. An empty array
is valid. The field is required, and each invalid item receives its own input
path, such as Policy.choices[1]. A comprehension can read a table cell for
each member in the submitted order, for example
sum(Charges[choice].charge for choice in policy.choices). Repeated members
contribute once per appearance.
Use a count in [1, 3] check on the field to require one to three entries.
The input schema exposes the same minimum and maximum, and the runtime
reports a length violation at the field path.
Narrow an enum input
A named subset such astype Polygon = Piece in {.rectangle, .triangle} retains
the member wire values from Piece. Use piece: Polygon to require an input
from that subset. An unknown wire value receives INPUT-ENUM. A wire value
that belongs to Piece but falls outside Polygon receives INPUT-REFINEMENT
at the input’s path.
Read a tagged input
A required tagged input takes a JSON object with atag and the fields for
that arm. For type Origin = { measured "Measured" { amount: Num }, estimated "Estimated" },
send {"tag":"Measured","amount":12} or {"tag":"Estimated"}. Match on the
source name, as in .measured m => m.amount. The request uses the declared
wire spelling, such as "Measured".
Use type Status = tagged { absent "Absent", recorded "Recorded" } when
every arm is empty. Send {"tag":"Recorded"} and match with .recorded.
An ordinary enum input takes the string "Recorded".
A scalar payload field can be optional or require a filed table key. Admission
checks the selected arm and reports an invalid value at its nested field path.
The input schema lists the closed alternatives in oneOf.
Look up a text code
AText input receives a JSON string. Use it for codes whose spelling matters.
For example, "0012" and "12" can name different rows, and sending the number
12 gives an input type refusal.
text-keys/rater.rsl
from "classes.csv" to the table declaration,
move the two filed rows to that file, and use class_code,factor,label as its header.
Exact key lookup preserves the text in each cell. A Text field can receive strings outside the table, so a
lookup using that field needs an otherwise row.
Require a filed table key
Write the table and key column, such asClasses.class_code, to admit only
values that name a filed row. This corresponds to Key(Classes) in a legacy
rater with one key column. The input keeps that column’s type and wire
representation. A table’s otherwise row does not make a value a filed key.
filed-keys/rater.rsl
or refuse to use the
standard INPUT-KEY-UNFILED response.
Both editions reserve the wire value unfiled for a blank cell in a table
output enum. Use another member value for a filed row. A Text output can
contain the literal word unfiled.
For a band lookup without a fallback, the compiler must prove that a computed
key stays inside the filed bands. A bounded input can still yield an
out-of-range key after subtraction. Check the bounds of the calculation,
including the first and last cut and the grid that the filing specifies.
Keep child records in the result
Addlayout nested to an RSL 0.5 rating entry when callers read child records. Use entry rate detail demand layout nested to combine nested results with demand-only detail.
The public and detailed results include the declared input record and list hierarchy. A present child produces an object with its published fields and nested child structure. An omitted or null optional child produces null. A list keeps request order and produces [] when empty. The layout does not echo scalar inputs.
Use the same show lines to publish calculation results. With detail demand, detailed results also include the calculations the rating evaluated. The input contract stays the same. Native and Worker readers need to support the layout before loading a bundle that uses it.
Publish calculations on an optional child
Withlayout nested, a for over an owned record field writes calculations
on that record. When the field is optional, the block has one instance if the
request supplies the child and no instance if the field is omitted or null.
Publish the child’s result inside the block, as you do for list items.
nested-child/rater.rsl
{"Policy":{"coverage":{"risk_charge":100}}} in the outputs. An omitted or
null coverage produces {"Policy":{"coverage":null}}. The entry’s
detail demand setting also keeps demanded calculations on the child.
Refer to a sibling record by key
A requiredRef(Driver) field can identify an item in a sibling List(Driver) on the immediate owner. Declare a key on Driver, then send the key as the reference field’s value. A calculation can read through the reference with a path such as vehicle.primary_driver.amount. Admission rejects duplicate list keys and references that have no matching item.
Use enum-indexed maps
Declare a required input such aslimit: Num[Coverage] @ 1 in [0, 100]. Send a JSON object with a value for every wire key in Coverage. The interval and grid apply to each cell. Read a cell with policy.limit[policy.coverage].
Define a calculated map with a declaration such as let charge[c: Coverage]: Num = policy.limit[c] * 2. Use show charge to publish the map as an object keyed by the enum’s wire values.
Choose the edition for your plan
The RSL 0.5 preview covers a subset of rating authoring with scalar and record inputs. Use RSL 0.4 for scenario evaluation withrslc eval, proof checks, underwriting and submission logs, or any rating form the preview refuses. Keep an existing rater in the edition it declares until you have compared the outcome and input contract of a rewritten version.
See Versions for the language, compiler, and bundle versions. See Programs on Effective for working with a completed bundle.