From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id EAA07914; Thu, 28 Jun 2001 04:48:45 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA07943 for ; Thu, 28 Jun 2001 04:48:44 +0200 (MET DST) Received: from smtp2-cm.mail.eni.net (smtp2-cm.mail.eni.net [216.133.226.135]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f5S2mhf26545 for ; Thu, 28 Jun 2001 04:48:43 +0200 (MET DST) Received: from CHECKERATH (node-d8e9cca2.powerinter.net [216.233.204.162]) by smtp2-cm.mail.eni.net (8.9.3/8.9.3) with SMTP id TAA15050 for ; Wed, 27 Jun 2001 19:48:42 -0700 Date: Wed, 27 Jun 2001 19:48:42 -0700 Message-Id: <200106280248.TAA15050@smtp2-cm.mail.eni.net> From: Chris Hecker To: caml-list@inria.fr Subject: [Caml-list] anonymous record copy? Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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