Browse thread
[Caml-list] Newbie question: semantics of 'mutable' in relation to deep / shallow copying of CAML values.
-
Gerard Murphy
- Daniel de Rauglaudre
- Alain Frisch
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Alain Frisch <frisch@c...> |
| Subject: | Re: [Caml-list] Newbie question: semantics of 'mutable' in relation to deep / shallow copying of CAML values. |
On Thu, 22 Nov 2001, Gerard Murphy wrote:
> # let value2 = value1;;
This is just a binding, no copy is involved: value1 and value2
simply denotes the same value. There are several methods to
create shallow copies of values:
- for objects: use Oo.copy or the {< >} notation
- for records: use the { r with ...} notation (you have to make
at least one field explicit !)
- for everything except objets, you can also use Obj.dup, but
you are not encouraged to do so !
To create deep copies, the only generic method, AFAIK, it to
marshal/unmarshal values:
let deep (x : 'a) : 'a = Marshal.from_string (Marshal.to_string x [Marshal.Closures]) 0;;
(add Marshal.No_sharing to the list if you don't want to keep sharing
inside the value)
I never felt the need for such an operation in OCaml, though.
--
Alain
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr