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 RAA16232; Mon, 15 Jul 2002 17:24:59 +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 RAA16218 for ; Mon, 15 Jul 2002 17:24:58 +0200 (MET DST) Received: from parsmtp2.rd.francetelecom.com (parsmtp2.rd.francetelecom.com [194.167.105.14]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g6FFOwn22153 for ; Mon, 15 Jul 2002 17:24:58 +0200 (MET DST) Received: from LANMHS20.rd.francetelecom.fr ([10.193.21.60]) by parsmtp2.rd.francetelecom.com with Microsoft SMTPSVC(5.0.2195.4905); Mon, 15 Jul 2002 17:24:57 +0200 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: [Caml-list] Deep copy X-MimeOLE: Produced By Microsoft Exchange V6.0.5762.3 Date: Mon, 15 Jul 2002 17:24:57 +0200 Message-ID: <0489A7888F080B4BA73B53F7E145F29A1B0AF5@LANMHS20.rd.francetelecom.fr> Thread-Topic: [Caml-list] Deep copy Thread-Index: AcIsEYHG7UX8dtopQD+ECprUUG/nEAAAFCng From: "zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN" To: "Eray Ozkural" Cc: X-OriginalArrivalTime: 15 Jul 2002 15:24:57.0901 (UTC) FILETIME=[C74565D0:01C22C13] Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > De : Eray Ozkural [mailto:erayo@cs.bilkent.edu.tr] > Envoy=E9 : lundi 15 juillet 2002 17:03 >=20 >=20 > On Monday 15 July 2002 13:06, zze-MARCHEGAY Michael stagiaire=20 > FTRD/DTL/LAN=20 > wrote: > > Hi all, > > > > I'm writting a program that manipulates a graph structure=20 > and I need to > > make deep copies of some of the graph nodes. The function=20 > Oo.copy donesn't > > perform a deep copy and I haven't found any other that=20 > could make it. >=20 > You mean something like creating a new object on the heap and=20 > copying over the=20 > contents of an existing object. >=20 > If this were C++ all you had to do would be invoking the copy=20 > constructor > Node* x =3D new Node(old_node); >=20 > From the documentation OO.copy does look like a deep copy operation: >=20 > val copy : < .. > -> < .. > > Oo.copy o returns a copy of object o, that is a fresh object=20 > with the same=20 > methods and instance variables as o In fact, if an object 'a' contains an attribute 'b' that is another=20 object, Oo.copy on 'a' gives a copy of 'a' in which the attribute 'b' is **physically** equal to the copied attribute from 'a'. Example: class a =3D=20 object=20 val mutable b =3D new b method get_b =3D b end and b =3D=20 object val mutable c =3D "1" method set_c x =3D c <- x method print_c =3D print_string ("c=3D" ^ c ^ "\n") =20 end let aa =3D new a let aa' =3D Oo.copy aa let _ =3D=20 aa#get_b#set_c "3"; aa#get_b#print_c; aa'#get_b#print_c gives: c=3D3 c=3D3 whereas a deep copy would give: c=3D3 c=3D1 >=20 > Curious, > =20 > --=20 > Eray Ozkural > Comp. Sci. Dept., Bilkent University, Ankara > www: http://www.cs.bilkent.edu.tr/~erayo > GPG public key fingerprint: 360C 852F 88B0 A745 F31B EA0F=20 > 7C07 AE16 874D 539C >=20 >=20 ------------------- 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