caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alain Frisch <frisch@clipper.ens.fr>
To: Gerard Murphy <gerard.murphy@sharp.co.uk>
Cc: <caml-list@inria.fr>
Subject: Re: [Caml-list] Newbie question: semantics of 'mutable' in relation to deep / shallow copying of CAML values.
Date: Thu, 22 Nov 2001 15:23:13 +0100 (MET)	[thread overview]
Message-ID: <Pine.GSO.4.33.0111221511520.17878-100000@clipper.ens.fr> (raw)
In-Reply-To: <11103C7901D5D411B45800508BB02D72012466E7@exchange1.sle.sharp.co.uk>

On Thu, 22 Nov 2001, Gerard Murphy wrote:

> #       let value2 = value1;;

This is just a binding, no copy is involved: value1 and value2
simply denotes the same value. There are several methods to
create shallow copies of values:
- for objects: use Oo.copy or the {< >} notation
- for records: use the { r with ...} notation (you have to make
  at least one field explicit !)
- for everything except objets, you can also use Obj.dup, but
  you are not encouraged to do so !

To create deep copies, the only generic method, AFAIK, it to
marshal/unmarshal values:

let deep (x : 'a) : 'a = Marshal.from_string (Marshal.to_string x [Marshal.Closures]) 0;;

(add Marshal.No_sharing to the list if you don't want to keep sharing
inside the value)

I never felt the need for such an operation in OCaml, though.

-- 
  Alain

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


      parent reply	other threads:[~2001-11-22 14:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-22 12:25 Gerard Murphy
2001-11-22 13:11 ` Daniel de Rauglaudre
2001-11-22 14:23 ` Alain Frisch [this message]

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=Pine.GSO.4.33.0111221511520.17878-100000@clipper.ens.fr \
    --to=frisch@clipper.ens.fr \
    --cc=caml-list@inria.fr \
    --cc=gerard.murphy@sharp.co.uk \
    /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).