Is it possible to write ref_of_array?

Not just hard, but plain impossible. Indeed, OCaml uses a garbage collector that requires every pointer to point to the start of a memory block and every memory block to be preceded by metadata. So, you cannot have a pointer to an array cell, as the previous cell would be interpreted as corrupted metadata by the garbage collector. (There is one exception: the very first cell of an array. You could convert it to a reference, as its metadata would then be sensible.)

2 Likes