Skip to main content

Records

Records are a structure holding multiple named inner types. For example:

{ number: 1, description: "One" }

The example defines a record structure with two fields: number, of type int and value 1, and description, of type string and value "One".

To access fields of a record, use ., as in:

let
example = { number: 1, description: "One" }
in
example.number // Result is 1

Records can be defined without named fields. In that case, a name is automatically created for the field, based on its position. For example:

{ 1, "One" }

The example defines a record structure with two fields: _1, of type int and value 1, and _2, of type string and value "One". The _<position> is automatically defined when the field name is missing. Named and unnamed fields can be mixed together. For example:

{ n: 1, "One" }

The example defines a record structure with two fields: n, of type int and value 1, and _2, of type string and value "One".

Records can contain twice the same field name. For instance, the following is a valid record definition:

{ x: 1, y: 2, x: 3 }

Note that the field x is defined twice. The field x cannot be accessed with . if it is defined twice. For example:

let
example = { x: 1, y: 2, x: 3 }
in
example.x // Error since 'x' is ambiguous,
// as both the first and third fields are called 'x'.

Instead, the field must be accessed by position as in:

let
example = { x: 1, y: 2, x: 3 }
in
Record.GetFieldByIndex(example, 1) // Result is '1'

Refer to the Record library documentation for additional operations on records.