From: Didier.Remy@inria.fr (Didier Remy)
To: garrigue@kurims.kyoto-u.ac.jp (Jacques GARRIGUE)
Cc: 100060.2106@compuserve.com, caml-list@pauillac.inria.fr
Subject: Re: Oo.copy
Date: Tue, 28 May 1996 15:06:42 +0200 (MET DST) [thread overview]
Message-ID: <199605281306.PAA08787@pauillac.inria.fr> (raw)
In-Reply-To: <199605281148.UAA15218@orion> from "Jacques GARRIGUE" at May 28, 96 08:48:24 pm
> The problem is that your array is shared between the two copies.
> There are various specific ways to solve it.
> One is to add an "unsharing" method in the virtual class, which is
> applied after copying.
>
> val mutable m = ...
> method unshare = m <- Array.map Array.copy m
> method copy = let o = Oo.copy m in o#unshare; o
>
> Then the problem is solved by using
> > let n = m#copy;;
A shorter way is
val m = ...
method copy = {< m = Array.map Array.copy m >}
This is also safer since the state m does not need to be mutable.
> This is difficult to have a general way, since mutable data structures
> can get various forms.
As you have understood, the function Oo.copy implements a superficial copy.
It would be possible to provide a (system) deep copy that would duplicate
the whole graph structure in the memory, using a mechanism similar the
implementation of export and import but not failing on functions. This copy
could also work for any ML value, not just objects. However, it is not clear
that this is often what the user wants, and we did not provide it.
Superficial and deep copy can be polymorphic other all objects and therefore
provided in a (system) library.
Any intermediate copy is arbitrary and therefore should be programmed by the
user, usually as a method of the corresponding objects.
Didier.
next prev parent reply other threads:[~1996-05-29 10:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-05-25 20:25 Oo.copy ESPERET PHILIPPE
1996-05-28 11:48 ` Oo.copy Jacques GARRIGUE
1996-05-28 13:06 ` Didier Remy [this message]
1996-05-28 18:43 Oo.copy Andrew Conway
1996-05-29 1:53 ` Oo.copy Jacques GARRIGUE
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=199605281306.PAA08787@pauillac.inria.fr \
--to=didier.remy@inria.fr \
--cc=100060.2106@compuserve.com \
--cc=caml-list@pauillac.inria.fr \
--cc=garrigue@kurims.kyoto-u.ac.jp \
/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