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=none autolearn=disabled version=3.1.3 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 9C458BBC1 for ; Mon, 3 Mar 2008 19:45:56 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAADbWy0eK54gDh2dsb2JhbACQdwEBAQgKKZwn X-IronPort-AV: E=Sophos;i="4.25,439,1199660400"; d="scan'208";a="7953577" Received: from rouge.crans.org ([138.231.136.3]) by mail2-smtp-roc.national.inria.fr with ESMTP; 03 Mar 2008 19:45:56 +0100 Received: from localhost (localhost.crans.org [127.0.0.1]) by rouge.crans.org (Postfix) with ESMTP id 2F1DD806A; Mon, 3 Mar 2008 19:45:56 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at crans.org Received: from rouge.crans.org ([10.231.136.3]) by localhost (rouge.crans.org [10.231.136.3]) (amavisd-new, port 10024) with LMTP id xUdjWSMpA864; Mon, 3 Mar 2008 19:45:56 +0100 (CET) Received: from [138.231.138.207] (doomeer.crans.org [138.231.138.207]) by rouge.crans.org (Postfix) with ESMTP id 0C9BF8065; Mon, 3 Mar 2008 19:45:55 +0100 (CET) Message-ID: <47CC4765.2080309@doomeer.com> Date: Mon, 03 Mar 2008 19:45:57 +0100 From: DooMeeR User-Agent: Thunderbird 2.0.0.12 (X11/20080227) MIME-Version: 1.0 To: mfmorss@aep.com Cc: caml-list caml-list Subject: Re: [Caml-list] different records, same field name? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; ocaml:01 toplevel:01 ocaml:01 toplevel:01 struct:01 caml-list:01 int:01 variant:02 variant:02 define:02 modules:02 string:02 string:02 defining:02 labels:03 mfmorss@aep.com a écrit : > I have not used OCaml, just done some reading about it and toyed with the > toplevel to see if it might be a useful tool here. I have "Practical > OCaml," which unfortunately is a rather wretched reference. > > In any case, is it possible to define and use different types of records, > which nevertheless share some field names? I have had difficulty doing > this in the toplevel. Sharing names for record labels, as well as for variant tags, is not a good idea. Indeed, only the last name is remembered (as for everything in OCaml), so the type system will infer the last type which has this label. One way to separate names is to use modules, for instance: module People = struct type t = { name: string; age: int; } end;; Then you can use labels People.name and People.age, for instance: let x = { People.name = "x"; age = 69; };; Notice how, when defining this variant, you don't have to use "People." for every label. x.People.name The toplevel gives you: - : string = "x" If you know you won't have any name clash, you can open module People and you won't have to use "People." everytime: open People;; let x = { name = "x"; age = 69; };; -- Romain Bardou