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 58CD5BBC4 for ; Tue, 14 Apr 2009 16:13:06 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AosAAAg35EmArgVglGdsb2JhbACWDgEBAQEJCwgJEQS5EQeDdQY X-IronPort-AV: E=Sophos;i="4.40,185,1238968800"; d="scan'208";a="38456961" 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 16:13:05 +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 n3EED32n011091; Tue, 14 Apr 2009 09:13:03 -0500 (CDT) To: caml-list@inria.fr Subject: pattern matching and records vs tuples From: Yoann Padioleau Date: Tue, 14 Apr 2009 09:12:19 -0500 Message-ID: <87skkbuxx8.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 ocaml:01 foo:01 tuples:01 tuples:01 int:01 int:01 tuple:02 exhaustive:03 let:03 let:03 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 :( So, would it be possible to extend the ocaml compiler with a simple feature that let the programmer tell the compiler when he use an "exhaustive" pattern with record, e.g. let foo = function { field1 = v1; field2 = v2; NOTHING_ELSE} -> (the inverse of a '...')