In this case, the memory for variable X will be copied. The last line of your code is just another way to write this:
let myRecord2 = { X = myRecord1.X; Y = 100; Z = 2 }
Now, if X has a reference type, the memory for the reference to it would be copied, but the memory for its contents would be shared.
For example, consider the following:
type MyX = { W: int; U: int } type MyRecord = { X: MyX; Y: int; Z: int } let myRecord1 = { X = { W = 5; U = 6 }; Y = 2; Z = 3; } let myRecord2 = { myRecord1 with Y = 100; Z = 2 }
In the above code, the memory for X will be copied, but the memory for W and U will be shared.
Fyodor soikin
source share