From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA08762; Thu, 22 Nov 2001 15:23:26 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA08364 for ; Thu, 22 Nov 2001 15:23:25 +0100 (MET) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id fAMENJr06782 for ; Thu, 22 Nov 2001 15:23:24 +0100 (MET) Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.10.1/1.01.28121999) with ESMTP id fAMENDU41849 ; Thu, 22 Nov 2001 15:23:13 +0100 (CET) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.9.2/jb-1.1) id PAA07010 ; Thu, 22 Nov 2001 15:23:13 +0100 (MET) Date: Thu, 22 Nov 2001 15:23:13 +0100 (MET) From: Alain Frisch To: Gerard Murphy cc: Subject: Re: [Caml-list] Newbie question: semantics of 'mutable' in relation to deep / shallow copying of CAML values. In-Reply-To: <11103C7901D5D411B45800508BB02D72012466E7@exchange1.sle.sharp.co.uk> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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