From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id ED4AFBC48 for ; Wed, 23 Mar 2005 20:41:06 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2NJf6EI028780 for ; Wed, 23 Mar 2005 20:41:06 +0100 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 UAA11157 for ; Wed, 23 Mar 2005 20:41:06 +0100 (MET) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.198]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2NJf57e028775 for ; Wed, 23 Mar 2005 20:41:05 +0100 Received: by rproxy.gmail.com with SMTP id a36so507896rnf for ; Wed, 23 Mar 2005 11:41:05 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding; b=IFvNKdOJ39FjKgXg7ytF8rcZOdbzY4SYiEnNTdnwYFMB8nQG3sPcXvZKC0r+WB9LsqEBXvxCheNhrN/ax8Cup1kW7KxPXktMzub2d99KoIK3LgybCPOJEQqj6BBd8G5OPdpl5N5aZt3igzXbEqQqdApxEAK6x5fx0UsS2M8iQT8= Received: by 10.38.75.67 with SMTP id x67mr491029rna; Wed, 23 Mar 2005 11:41:04 -0800 (PST) Received: by 10.38.97.56 with HTTP; Wed, 23 Mar 2005 11:41:04 -0800 (PST) Message-ID: <88707140050323114156bcb9fb@mail.gmail.com> Date: Wed, 23 Mar 2005 13:41:04 -0600 From: Jeffrey Cook Reply-To: Jeffrey Cook To: caml-list@inria.fr Subject: Records with default values Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 4241C652.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4241C651.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; foo:01 foo:01 uglier:01 runtime:01 runtime:01 uncaught:01 annotation:01 'x':01 defining:01 exceptions:01 define:01 explicitly:01 checking:01 defined:01 defined:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.2 X-Spam-Level: Is there an existing (or even possible to do with) camlp4 extension to support default values in records? I am constantly finding myself doing the following: type bob = { foo : string ; <--- field for which no default value makes sense bar : int ; <--- field(s) that have default values } let bob_default = { foo = ""; bar = 0; } with usage: let x = { bob_default with foo = "hello" } so that I do not have to fill in the numerous fields that really should default to some value. Without using this solution, my code is often cluttered with many doldrum default value declarations for record fields (worsened by multiple sites that define the initial record values), obscuring what the important assignments were. Additionally, I often find that the complex fields (of record types, for example) are the ones that don't lend themselves to a default value whereas the simple types do. This leads to the use of options (discussed below) just to save from even uglier default value declarations for fields that never use a default. Using a default structure like above also does not let me harness the type checking mechanisms to detect places in my code where a field (that really shouldn't have a default value) wasn't defined as is normally the case when constructing a record from scratch - especially when fields are later added to the record. Using 'options' for no-default-value fields doesn't seem to be a very good solution, as there then need to be runtime deconstructors of the options (and runtime checks or uncaught exceptions) if a field has a None value that should have been set. All that aside, it still wouldn't identify where the record was incompletely 'created' using the default record. What I would like is the following: type bob = { foo : string ; bar : int := 0 ; } let x = { foo = "hello" } (and maybe even some kind of 'nodefaults' annotation when defining 'x' if I want to make sure I've explicitly defined every field.) So what advice / solutions do other people have / use? Thanks. Jeffrey Cook Ph.D. Candidate, Electrical Engineering University of Illinois at Urbana-Champaign jeffrey.j.cook@gmail.com