Record accessors
The record accessor syntax record.field_label
can be used to get
contained values from a custom type record.
The accessor syntax can always be used for fields with the same name that are in the same position and have the same type for all variants of the custom type. Other fields can only be accessed when the compiler can tell which variant the value is, such after pattern matching in a `case` expression.
The name
field is in the first position and has type
String
for all variants, so it can be accessed.
The subject
field is absent on the Student
variant,
so it cannot be used on all values of type SchoolPerson
.
Uncomment the student.subject
line to see the compile error from
trying to use this accessor.