Record updates on OCaml types with private fields
0 reputation · 07 Jun 2024, 11:21 UTC
Record updates on OCaml types with private fields
Goal: clarify whether updating a non-private field is permitted when the record type’s signature declares another field private.
OCaml’s private modifier blocks external mutation of that field, but it is unclear whether updating a sibling field is rejected because the operation copies the private field into a new record value. The answer may depend on whether the record type is concrete or abstract in the signature.
Version assumption: OCaml 5.x; private behavior is reported as stable since OCaml 3.12.
- Does updating field
yvia record-update syntax compile when fieldxisprivateandyis mutable? - If it compiles, is
xcopied unchanged, or does the update count as modifying a private field? - Does fresh record construction outside the module face the same restriction?