RIP
Tutorial
Tags
Topics
Examples
eBooks
Tutorial by Examples
Declaring a record with mutable fields
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
Initializing a record with mutable fields isn't different from a regular record initialization. let john = { name = "John"; weight = 115 };;
Setting the value to a mutable field
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
1
Cookie
This website stores cookies on your computer.
We use cookies to enhance your experience on our website and deliver personalized content.
For more details on our cookie usage, please review our
Cookie Policy
and
Privacy Policy
Accept all Cookies
Leave this website