Chapter 9 : Records

Records are like tuples but with named parameters. In other words, they hold a set of key/data pairs. To instantiate a record, you must first declare its type as follows :

type user = {
  id       : nat,
  is_admin : bool,
  name     : string
};

And here is how to define an associated record value :

let alice : user = {
  id       : 1 as nat,
  is_admin : true,
  name     : "Alice"
};

Access

You can access the whole record or get one key in particular :

let alice_admin: bool = alice.is_admin;

Update

You can modify values in a record as follows :

let change_name = (u: user): user => ({...u, name: "Mark"});

⚠️ Note that user has not been changed by the function. Rather, the function returned a nameless new version of it with the modified name.

Your mission

1- Refactor the type of coordinates as a record instead of a tuple. Name the parameters x, y and z.

2- Refactor earth_coordinates with the record type.

2- Refactor the earth_coordinates update of the last parameters with the record type.