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=1.5 required=5.0 tests=AWL,DNS_FROM_RFC_POST autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id EA543BBC4 for ; Tue, 14 Apr 2009 18:59:12 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AokAALNd5EmArgVglGdsb2JhbACWDwEBAQEJCwgJEQS6GQeDdQY X-IronPort-AV: E=Sophos;i="4.40,186,1238968800"; d="scan'208";a="38467928" Received: from expredir5.cites.uiuc.edu ([128.174.5.96]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 14 Apr 2009 18:59:12 +0200 Received: from axyr (aryx.cs.uiuc.edu [128.174.236.106]) by expredir5.cites.uiuc.edu (8.14.2/8.14.2) with ESMTP id n3EGx9nj004949; Tue, 14 Apr 2009 11:59:10 -0500 (CDT) To: Goswin von Brederlow Cc: Yoann Padioleau , caml-list@inria.fr Subject: Re: [Caml-list] pattern matching and records vs tuples References: <87skkbuxx8.fsf@aryx.cs.uiuc.edu> <87tz4ryyrb.fsf@frosties.localdomain> From: Yoann Padioleau Date: Tue, 14 Apr 2009 11:58:26 -0500 In-Reply-To: <87tz4ryyrb.fsf@frosties.localdomain> (Goswin von Brederlow's message of "Tue\, 14 Apr 2009 18\:40\:40 +0200") Message-ID: <87myajuq8d.fsf@aryx.cs.uiuc.edu> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam: no; 0.00; compiler:01 compiler:01 foo:01 ocaml:01 'foo':01 mfg:98 partial:01 caml-list:01 tuples:01 tuples:01 pairs:01 int:01 int:01 writes:01 writes:01 Goswin von Brederlow writes: > 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. > I didn't say records have only disadvantages. > 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. Ok ... Sometimes people want the partial match behavior, but sometimes people prefer another behavior, so I just propose a kind of annotation in the pattern that describes what behavior the programmer wants. > > MfG > Goswin