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 SAA06517; Fri, 14 May 2004 18:22:07 +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 SAA06557 for ; Fri, 14 May 2004 18:22:06 +0200 (MET DST) Received: from francois.mpi-sb.mpg.de (mpiat0203-1.mpi-sb.mpg.de [139.19.1.2]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i4EGM5EV029072 for ; Fri, 14 May 2004 18:22:05 +0200 Received: from amavis by francois.mpi-sb.mpg.de with scanned-ok (Exim 3.35 #1 (Debian)) id 1BOfRl-0007Uc-00 for ; Fri, 14 May 2004 18:22:05 +0200 Received: from data ([139.19.90.238] helo=mpi-sb.mpg.de) by francois.mpi-sb.mpg.de with esmtp (Exim 3.35 #1 (Debian)) id 1BOfRh-0007Th-00; Fri, 14 May 2004 18:22:01 +0200 Received: from mpiat2314 (mail@mpiat2314 [139.19.20.103]) by mpi-sb.mpg.de (8.12.9+Sun/8.12.9) with ESMTP id i4EGM1QU004405; Fri, 14 May 2004 18:22:01 +0200 (MEST) Received: from localhost ([127.0.0.1] helo=mpiat2314 ident=prevosto) by mpiat2314 with smtp (Exim 3.35 #1 (Debian)) id 1BOfRh-0005wH-00; Fri, 14 May 2004 18:22:01 +0200 Date: Fri, 14 May 2004 18:22:01 +0200 From: Virgile Prevosto To: David Fox Cc: Ocaml Subject: Re: [Caml-list] "changing" immutable record elements Message-Id: <20040514182201.3c40ea26@mpiat2314> In-Reply-To: <40A4EAC8.2080905@lindows.com> References: <40A4EAC8.2080905@lindows.com> X-Mailer: Sylpheed version 0.9.10claws (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by AMaViS perl-11 X-Miltered: at nez-perce with ID 40A4F22D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; virgile:01 prevosto:01 prevosto:01 caml-list:01 immutable:01 prettier:01 virgile:01 htmlman:01 ecrit:01 ocaml:01 ocaml:01 0700,:01 rec:01 rec:01 match:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Le vendredi 14 mai, =E0 8h50 -0700, David Fox a =E9crit: > Unless I am missing some core language feature, it seems to me that > the most awkward part of the language is constructing an expression > that represents a record with a single field modified: >=20 > let set_field3 rec value =3D > match rec with > {field1=3Dfield1; field2=3Dfield2; field3=3Dfield3; field4=3Dfield= 4;=20 > field5=3Dfield5} -> > {field1=3Dfield1; field2=3Dfield2; field3=3Dvalue; field4=3Dfie= ld4;=20 > field5=3Dfield5} >=20 > is there any prettier way of doing this? Yes, let set_field_3 my_rec v =3D {my_rec with field3=3Dv}=20 (cf http://pauillac.inria.fr/ocaml/htmlman/manual015.html, section 6.7.3) By the way, rec and value are keywords in ocaml. you might run into trouble if you try to use them as identifiers ;-) --=20 E tutto per oggi, a la prossima volta Virgile ------------------- 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