Let’s look at reference capabilities, starting with the most basic one: ref
.
Here we declare a type Person'ref
, with two fields, a ref
constructor, and a ref
function called birthday
that increments the age field by one year.
The birthday
function is able to modify the age field because ref
denotes a mutable type - mutation must be explicitly permitted in the type system by using a mutable reference capability, and a function declared as ref
means that the value that receives the function call is required to be in a mutable state.