So, OCaml uses a lot of immutable data structures by default, and there's a way in OCaml to express how to replace everything else in a type with the same edition, with the exception of a single variable being updated.


But does that mean that the compiler is sufficiently capable to conclude side effects that are more efficient rather than just the nieve explanation, which is a *copy* of the entire data structure with only the specified changed variable updated? Can OCaml conclude that it can update only one variable for efficiency, and know that the rest of the data structure is safe?

For example, in tail recursion, it's provably equivalent to produce code that doesn't blow the stack and is faster, and that's exactly what the compiler does. So are side effects a "conclusion"?