From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id CA13DBBC4 for ; Tue, 14 Apr 2009 18:40:42 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgsHAANZ5EnZSMDdZGdsb2JhbACBUpQwGgsDBwcPBbo+g3wG X-IronPort-AV: E=Sophos;i="4.38,431,1233529200"; d="scan'208";a="27668711" Received: from fmmailgate01.web.de ([217.72.192.221]) by mail1-smtp-roc.national.inria.fr with ESMTP; 14 Apr 2009 18:40:42 +0200 Received: from smtp05.web.de (fmsmtp05.dlan.cinetic.de [172.20.4.166]) by fmmailgate01.web.de (Postfix) with ESMTP id EF984FFEA1A9; Tue, 14 Apr 2009 18:40:41 +0200 (CEST) Received: from [78.43.226.218] (helo=frosties.localdomain) by smtp05.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #277) id 1Ltlgf-0007dY-00; Tue, 14 Apr 2009 18:40:41 +0200 Received: from mrvn by frosties.localdomain with local (Exim 4.69) (envelope-from ) id 1Ltlge-0008Lj-Mi; Tue, 14 Apr 2009 18:40:40 +0200 From: Goswin von Brederlow To: Yoann Padioleau Cc: caml-list@inria.fr Subject: Re: [Caml-list] pattern matching and records vs tuples References: <87skkbuxx8.fsf@aryx.cs.uiuc.edu> Date: Tue, 14 Apr 2009 18:40:40 +0200 In-Reply-To: <87skkbuxx8.fsf@aryx.cs.uiuc.edu> (Yoann Padioleau's message of "Tue, 14 Apr 2009 09:12:19 -0500") Message-ID: <87tz4ryyrb.fsf@frosties.localdomain> User-Agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.4.21 (linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX19HJ1w8ZLcdkWhQ8SkjTx4ja0+Vh5H6MFemNp6N Bc2QGZ+Pj5mDOvIrHBqUxIyGGR0uwM+znXWcnJddBq4J3rzCWA 4zacEFVJE= X-Spam: no; 0.00; compiler:01 compiler:01 foo:01 ocaml:01 'foo':01 mfg:98 caml-list:01 tuples:01 tuples:01 pairs:01 int:01 int:01 writes:01 partially:02 tuple:02 Yoann Padioleau writes: > Hi, > > I've found that while records provide advantages over tuples, > they also have disadvantages when it comes to evolution issues. > If I decide to evolve code using a tuple type, for instance adding > new information and so extend a 4-uple in a 5-uple, then the compiler > will tell me all the places that I need to update, which is good. > If I use records instead, and have 4 fields, and I want to add again > some new information in a new field, then the way the compiler works > right now will not help me at all. E.g with this code > > type record = { > field1: int; > field2: int; > } > let foo = function > { field1 = v1; field2 = v2 } -> ... > > > If I extend record with a new field field3, then ocaml will > not warn me and tell me to modify also the 'foo' function :( On the other hand that is a verry good thing. let set_field1 r x = { r with field1 = x } let set_field2 r x = { r with field2 = x } Try doing that with tuples and then add a 3rd, 4th, 5th field. I have to say I didn't even know you could match a record partially or have ever wanted to match a record at all. I use record only when I have a collection of otherwise independent values. As such any matching will be done on a single component of the record but never pairs of them. At least I can't remember having done so before. MfG Goswin