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 VAA19110; Sun, 14 Sep 2003 21:32:58 +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 VAA13883 for ; Sun, 14 Sep 2003 21:32:57 +0200 (MET DST) Received: from mail.speakeasy.net (mail11.speakeasy.net [216.254.0.211]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h8EJWuT22371 for ; Sun, 14 Sep 2003 21:32:56 +0200 (MET DST) Received: (qmail 12808 invoked from network); 14 Sep 2003 19:32:52 -0000 Received: from unknown (HELO grace.speakeasy.org) ([216.254.0.2]) (envelope-sender ) by mail11.speakeasy.net (qmail-ldap-1.03) with DES-CBC3-SHA encrypted SMTP for ; 14 Sep 2003 19:32:52 -0000 Date: Sun, 14 Sep 2003 12:32:52 -0700 (PDT) From: brogoff@speakeasy.net To: Olivier Andrieu cc: "Eric C. Cooper" , "caml-list@inria.fr" Subject: Re: [Caml-list] suggestion for record pattern matching and construction In-Reply-To: <16223.45432.216362.752939@karryall.dnsalias.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Loop: caml-list@inria.fr X-Spam: no; 0.00; brogoff:01 caml-list:01 andrieu:01 nontrivial:01 camlp:01 inclined:01 bindings:01 speakeasy:01 labels:01 labels:01 sep:01 syntax:02 syntax:02 olivier:02 module:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 11 Sep 2003, Olivier Andrieu wrote: > Eric C. Cooper [Wednesday 10 September 2003] : > > > > I find that I am often writing code like > > { field1 = field1; field2 = field2; field3 = field3 } > > when matching and constructing records. I guess it's because thinking > > up good names for the record fields is nontrivial and having similar > > but different names for the bindings just bothers me. > > > > How about allowing syntax like that used for labels: > > { ~field1; ~field2; ~field3 } > > would expand into the above, in both pattern matching and construction > > contexts. > > I have a camlp4 extension that does exactly this (well, without > the ~). Also, you can put the module path before the { instead of > having to repeat it for each field. So : > > Mod1.Mod2.{ field1; field2 } > > is expanded into > > { Mod1.Mod2.field1 = field1 ; Mod1.Mod2.field2 = field2 } I like it, though I can even see an argument for the ~ syntax Eric suggests as it dovetails nicely with labels. I especially like your sugar which reduces the number of module qualifications. Is there any chance we could see a feature like this in the core language syntax? Especially since 3.07, I am more inclined to use "private" record types a lot more, and since I'd also like to minimize my use of open, this lighter syntax makes it even more appealing. -- Brian ------------------- 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