Search⌘ K

Nested Records

Explore how to create nested records in ReasonML by defining nested record types and incorporating sub-records into main records. Understand punning techniques to simplify your code and make complex data structures more manageable.

Type Nesting

In order to create nested records, we must first create nested record types. Once the record’s type structure allows nesting, we’ll have no problem creating nested records.

So, let’s work on our wizardInfo example from the previous lesson. We’ll be defining the schoolInfo type which contains the attributes school and house:

Reason
type schoolInfo = {
school: string,
house: string
};
/* Nesting schoolInfo into the wizardInfo type */
type wizardInfo = {
name: string,
age: int,
schoolAndHouse: schoolInfo
};
...