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 RAA16391; Mon, 15 Jul 2002 17:28:48 +0200 (MET DST) 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 RAA16274 for ; Mon, 15 Jul 2002 17:28:47 +0200 (MET DST) Received: from mel-rto4.wanadoo.fr (smtp-out-4.wanadoo.fr [193.252.19.23]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g6FFSln22226 for ; Mon, 15 Jul 2002 17:28:47 +0200 (MET DST) Received: from mel-rta7.wanadoo.fr (193.252.19.61) by mel-rto4.wanadoo.fr (6.5.007) id 3D18589F00AF09CB; Mon, 15 Jul 2002 17:28:38 +0200 Received: from warp (217.128.142.232) by mel-rta7.wanadoo.fr (6.5.007) id 3D2A78FA003077FE; Mon, 15 Jul 2002 17:28:38 +0200 Message-ID: <000d01c22c14$2f99c590$9400a8c0@warp> From: "Nicolas Cannasse" To: "Eray Ozkural" , "OCaml" References: <0489A7888F080B4BA73B53F7E145F29A1B0AF3@LANMHS20.rd.francetelecom.fr> <200207151802.44699.erayo@cs.bilkent.edu.tr> Subject: Re: [Caml-list] Deep copy Date: Mon, 15 Jul 2002 17:27:28 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > I'm writting a program that manipulates a graph structure and I need to > > make deep copies of some of the graph nodes. The function Oo.copy donesn't > > perform a deep copy and I haven't found any other that could make it. > > You mean something like creating a new object on the heap and copying over the > contents of an existing object. > > If this were C++ all you had to do would be invoking the copy constructor > Node* x = new Node(old_node); Errr.... You're supposing here that either the copy constructor is implemented by the class writer or then that you're using the default copy constructor which only copy fields, and then do not perform any deep-recursion... It's even worst because pointers are duplicated so you can get very-unsafe behavior... > From the documentation OO.copy does look like a deep copy operation: > > val copy : < .. > -> < .. > > Oo.copy o returns a copy of object o, that is a fresh object with the same > methods and instance variables as o The "copy" notion is ambiguous, especially when you have mutable fields. Does the modification of such a field on a copy of an object do influence the original object ? Or is copy only the image of an object at a given time ? And what if the object manipulate opened streams ? Not so easy to resolve... I would recommand then to write a copy operator "by hand". Nicolas Cannasse ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners