Skip to main content
RSL is statically typed. Each input and each calculation states its type, and the check holds every expression to it. A type also carries facts about its values, such as a range, and the check uses those facts to show each operation safe.

The types

The language reference gives the form and the rules of each one.

A value keeps its type

RSL has zero implicit conversions. This calculation adds a Bool to a number:
convert/rater.rsl
An expression states the conversion it wants, such as if self.c then 1 else 0.

A type carries facts

A numeric input states its precision and its range:
The where clause is a refinement: it narrows the type to the values that pass it. A request with a value outside the range is refused before any calculation runs. From the facts of the inputs, the check works out the facts of each calculation. This one declares a range of 0 to 5 for the sum of two inputs:
range/rater.rsl
The check tracks these facts about a value:

A condition narrows a type

Inside a branch, the check knows what the condition says. Here the divisor has the range -9 to 9, and the guard removes 0 from it:
narrow/rater.rsl
A match narrows in the same way: the arm Some(v) => reads a present value, and each arm of an enumeration reads one member.

Absence is a type

RSL is free of null. A value that can be absent has the type Option(T), and a calculation reads it with a match on both cases. A read that skips a case gets E-OPTION-MATCH. A follow-up input is asked only under a condition. A calculation reads it under that condition, so an unasked question stays distinct from an answer of false.

Lists and maps

A plain List(Record) keeps the order of the request. A list declared keyed by is a map from key to record: its order is free to change, and a selection breaks a tie by the key. Lists and keys gives the rules.

What the type system leaves out

  • Generic types and user-defined functions. The functions are a fixed list, in the function reference.
  • Arithmetic on units. Premium, Rate, Factor and Pct state the role of a number, and each is an exact rational. This sum of a premium and a factor compiles:
units/rater.rsl
The check does flag one case: a Premium whose expression holds only factors.