caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Deep copy
@ 2002-07-15 10:06 zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN
  2002-07-15 13:42 ` Ken Wakita
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN @ 2002-07-15 10:06 UTC (permalink / raw)
  To: caml-list

Hi all,

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.

Actually, the nodes of my graph are specified using a lot inheritance, and if
I want to write specific "copy" methods for them, I will need to disperse the
clonning actions downto the leaf of my inheritance tree.

So I'd like to know is there is a clean way to make a deep copy of any object.

Thank you.

--
Michaël Marchegay, Stagiaire France Telecom R&D du 11/02/2002 au 26/07/2002
Sous la responsabilité d'Olivier Dubuisson
DTL/TAL - 22307 Lannion Cedex - France
-------------------
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


^ permalink raw reply	[flat|nested] 16+ messages in thread
* RE: [Caml-list] Deep copy
@ 2002-07-15 15:24 zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN
  2002-07-15 15:24 ` Eray Ozkural
  2002-07-15 19:53 ` Alessandro Baretta
  0 siblings, 2 replies; 16+ messages in thread
From: zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN @ 2002-07-15 15:24 UTC (permalink / raw)
  To: Eray Ozkural; +Cc: caml-list

> De : Eray Ozkural [mailto:erayo@cs.bilkent.edu.tr]
> Envoyé : lundi 15 juillet 2002 17:03
> 
> 
> On Monday 15 July 2002 13:06, zze-MARCHEGAY Michael stagiaire 
> FTRD/DTL/LAN 
> wrote:
> > Hi all,
> >
> > 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);
> 
> 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

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 <- 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

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


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2002-07-16  8:13 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-15 10:06 [Caml-list] Deep copy zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN
2002-07-15 13:42 ` Ken Wakita
2002-07-15 14:43   ` Eray Ozkural
2002-07-15 15:33     ` Ken Wakita
2002-07-15 23:09   ` Ken Wakita
2002-07-15 15:02 ` Eray Ozkural
2002-07-15 15:27   ` Nicolas Cannasse
2002-07-15 15:40     ` Eray Ozkural
2002-07-15 16:22 ` sebastien FURIC
2002-07-15 15:24 zze-MARCHEGAY Michael stagiaire FTRD/DTL/LAN
2002-07-15 15:24 ` Eray Ozkural
2002-07-15 18:18   ` Alessandro Baretta
2002-07-15 19:53 ` Alessandro Baretta
2002-07-15 22:35   ` John Prevost
2002-07-15 23:03     ` Alessandro Baretta
2002-07-16  8:19       ` John Prevost

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).