caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Eray Ozkural <erayo@cs.bilkent.edu.tr>
To: "Nicolas Cannasse" <warplayer@free.fr>, "OCaml" <caml-list@inria.fr>
Subject: Re: [Caml-list] Deep copy
Date: Mon, 15 Jul 2002 18:40:25 +0300	[thread overview]
Message-ID: <200207151840.25312.erayo@cs.bilkent.edu.tr> (raw)
In-Reply-To: <000d01c22c14$2f99c590$9400a8c0@warp>

On Monday 15 July 2002 18:27, Nicolas Cannasse wrote:
>
> 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...
>

You're right. A default deep copy probably wouldn't work for most applications 
:) That's why you usually have to write your own copy constructor in C++. 
Still it is a convenient thing to have a "clone" function that can do it. 
Even in the presence of recursive definitions and such it ought to be 
possible.

This could be useful when one has objects for data structures... Though it 
could be said it is a better style to use recursive types and the module 
system when you are doing complex data structures, cloning looks like one of 
those handy features that you expect from an object system.

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

I think Michael made that clear. Oo.copy does a shallow copy, it provides that 
all members of the new object will have physical equivalence to the given 
object. Therefore, modifying a mutable field on a copy should influence the 
original one.

The best kludge here would be to write an external function for all types that 
need the deep copy as you suggest. He could write his own copy function 
instead of Oo.copy

Writing a copy method inside each class would look worse :)

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


  reply	other threads:[~2002-07-15 15:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-15 10:06 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200207151840.25312.erayo@cs.bilkent.edu.tr \
    --to=erayo@cs.bilkent.edu.tr \
    --cc=caml-list@inria.fr \
    --cc=warplayer@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).