caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Chris Hecker <checker@d6.com>
To: caml-list@inria.fr
Subject: [Caml-list] anonymous record copy?
Date: Wed, 27 Jun 2001 19:48:42 -0700	[thread overview]
Message-ID: <200106280248.TAA15050@smtp2-cm.mail.eni.net> (raw)


How do you copy a record without a) updating anything in the record,
and b) not knowing the type of the record?

type foo = { mutable bar : int }

let a = { bar = 12 }

let copy_record = ???  

(* hopefully copy_record is 'a -> 'a, not foo -> foo *)

let b = copy_record a

b.bar <- 234  (* should not modify a.bar *)

There is Obj.dup, but it's in obj.ml, so that's bad, right?  There
doesn't seem to be a way to use the "with" update syntax in a
polymorphic and generic way, and you always have to specify a field
name to update anyway.  For any individual type, I could just reassign
all the values (or update a single field), but that's really bad mojo
when you're changing your records during development.  There's also
Oo.copy, but that doesn't work on records.

Any ideas, or rationale of why this isn't possible?

Chris

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


             reply	other threads:[~2001-06-28  2:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-28  2:48 Chris Hecker [this message]
2001-06-28  3:42 ` 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=200106280248.TAA15050@smtp2-cm.mail.eni.net \
    --to=checker@d6.com \
    --cc=caml-list@inria.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).