Deepcopy: Difference between revisions

Line 348:
end else failwith "copy" ;;
 
let copy (v : 'a) : 'a = Obj.obj (copy (Obj.repr v))</lang>
let copy = (copy : 'a -> 'a)</lang>
 
OCaml programmers will prefer to use specialised copy functions for each mutable types. For base types like strings and arrays, the standard library provides copy functions: <code>String.copy</code> and <code>Array.copy</code>. For mutable user-defined data structures, we will create a copy function based on these previous copy functions. For example in the module [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Hashtbl.html <code>Hashtbl</code>], the type is a record containing an integer and an array, so the copy function is defined as below:
Anonymous user