LearnDataRecords

Records

Group named fields in one value.

A record groups named fields. Use it when field names are the important part of the value.

let point := { x := 3, y := 4 };
let moved := { ...point, y := 9 };
moved;

Build and update records

let point := { x := 3, y := 4 };
let moved := { ...point, y := 9 };

Field values use :=. Spread ...point copies fields from another record before the later fields replace or add values.

Read fields

let x := point.x;
let y := moved.y;

A field read should be boring. If many records share behavior, use a function or shape instead of repeating field logic everywhere.

Records versus data

Use a record for a product shape: all listed fields exist together. Use data for a sum shape: exactly one variant exists at a time.

Record field operator

Record literals use := for each field because each field receives a value.

let point := { x := 3, y := 4 };

Use . to read a field:

let x := point.x;

If a field name is not clear, rename the field. Do not rely on a comment to explain a bad field name.