Tutorial by Examples

In the following, weight is declared as a mutable field. type person = { name: string; mutable weight: int };; Remark: As far as design is concerned here, one would consider the fact that a person's name isn't likely to change, but their weight is.
Initializing a record with mutable fields isn't different from a regular record initialization. let john = { name = "John"; weight = 115 };;
To assign a new value to a mutable record field, use the <- operator. john.weight <- 120;; Note: The previous expression has a unit type.

Page 1 of 1