<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/07/f588263f2499215c76c4696e61086612"
  from="zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN &lt;michael.marchegay@r...&gt;"
  author="zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN"
  date="2002-07-15T15:24:59"
  subject="RE: [Caml-list] Deep copy"
  prev="2002/07/a015dff01822b58f3bda38298a9a737c"
  next="2002/07/4f925d88bf549c83906ef318da735378"
  next-in-thread="2002/07/0908d34fdb197e026aad915879cf4cd2"
  prev-thread="2002/07/a6ba0ce22f3d5db7ef94de3a44da9825"
  next-thread="2002/07/2fe55408b32aa0c8bbfe694c2fc4d83a"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="RE: [Caml-list] Deep copy">
<msg 
  url="2002/07/f588263f2499215c76c4696e61086612"
  from="zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN &lt;michael.marchegay@r...&gt;"
  author="zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN"
  date="2002-07-15T15:24:59"
  subject="RE: [Caml-list] Deep copy">
<msg 
  url="2002/07/0908d34fdb197e026aad915879cf4cd2"
  from="Eray Ozkural &lt;erayo@c...&gt;"
  author="Eray Ozkural"
  date="2002-07-15T15:30:19"
  subject="Re: [Caml-list] Deep copy">
<msg 
  url="2002/07/72c2dc79654035cd9f28bd2d5e20f330"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-15T18:11:41"
  subject="Re: [Caml-list] Deep copy">
</msg>
</msg>
<msg 
  url="2002/07/e05cd085c84fab343d2798f03cabcf5e"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-15T19:46:53"
  subject="Re: [Caml-list] Deep copy">
<msg 
  url="2002/07/15f5a5b0e7c6ba77a94ba8a6b6e1d150"
  from="John Prevost &lt;j.prevost@c...&gt;"
  author="John Prevost"
  date="2002-07-15T22:28:33"
  subject="Re: [Caml-list] Deep copy">
<msg 
  url="2002/07/101f631797d254be4dac4a73b379b0ee"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-15T22:56:31"
  subject="Re: [Caml-list] Deep copy">
<msg 
  url="2002/07/f49c5a97e201b0f6ea5977beb5930c17"
  from="John Prevost &lt;j.prevost@c...&gt;"
  author="John Prevost"
  date="2002-07-16T08:13:08"
  subject="Re: [Caml-list] Deep copy">
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
&gt; De : Eray Ozkural [mailto:erayo@cs.bilkent.edu.tr]
&gt; Envoyé : lundi 15 juillet 2002 17:03
&gt; 
&gt; 
&gt; On Monday 15 July 2002 13:06, zze-MARCHEGAY Michael stagiaire 
&gt; FTRD/DTL/LAN 
&gt; wrote:
&gt; &gt; Hi all,
&gt; &gt;
&gt; &gt; I'm writting a program that manipulates a graph structure 
&gt; and I need to
&gt; &gt; make deep copies of some of the graph nodes. The function 
&gt; Oo.copy donesn't
&gt; &gt; perform a deep copy and I haven't found any other that 
&gt; could make it.
&gt; 
&gt; You mean something like creating a new object on the heap and 
&gt; copying over the 
&gt; contents of an existing object.
&gt; 
&gt; If this were C++ all you had to do would be invoking the copy 
&gt; constructor
&gt;  Node* x = new Node(old_node);
&gt; 
&gt; From the documentation OO.copy does look like a deep copy operation:
&gt; 
&gt; val copy : &lt; .. &gt; -&gt; &lt; .. &gt;
&gt; Oo.copy o returns a copy of object o, that is a fresh object 
&gt; with the same 
&gt; methods and instance variables as o

In fact, if an object 'a' contains an attribute 'b' that is another 
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 = 
  object 
    val mutable b = new b
    method get_b = b
  end
and b = 
  object
    val mutable c = "1"
    method set_c x =  c &lt;- x
    method print_c = print_string ("c=" ^ c ^ "\n")  
  end

let aa = new a
let aa' = Oo.copy aa

let _ = 
  aa#get_b#set_c "3";
  aa#get_b#print_c;
  aa'#get_b#print_c

gives:
c=3
c=3

whereas a deep copy would give:
c=3
c=1

&gt; 
&gt; Curious,
&gt;  
&gt; -- 
&gt; Eray Ozkural &lt;erayo@cs.bilkent.edu.tr&gt;
&gt; Comp. Sci. Dept., Bilkent University, Ankara
&gt; www: http://www.cs.bilkent.edu.tr/~erayo
&gt; GPG public key fingerprint: 360C 852F 88B0 A745 F31B  EA0F 
&gt; 7C07 AE16 874D 539C
&gt; 
&gt; 
-------------------
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

</contents>

</message>

