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.2 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id E176BBC70 for ; Wed, 22 Aug 2007 20:06:28 +0200 (CEST) Received: from 27.mail-out.ovh.net (27.mail-out.ovh.net [213.186.38.137]) by discorde.inria.fr (8.13.6/8.13.6) with SMTP id l7MGW4MR010039 for ; Wed, 22 Aug 2007 18:32:04 +0200 Received: (qmail 29848 invoked by uid 503); 22 Aug 2007 16:34:18 -0000 Received: from gw2.ovh.net (HELO mail186.ha.ovh.net) (213.251.189.202) by 27.mail-out.ovh.net with SMTP; 22 Aug 2007 16:34:18 -0000 Received: from b0.ovh.net (HELO queue-out) (213.186.33.50) by b0.ovh.net with SMTP; 22 Aug 2007 16:31:33 -0000 Received: from vil93-4-82-227-140-227.fbx.proxad.net (HELO ?192.168.1.222?) (82.227.140.227) by ns0.ovh.net with SMTP; 22 Aug 2007 16:31:33 -0000 Message-ID: <46CC6502.5090003@philippewang.info> Date: Wed, 22 Aug 2007 18:32:02 +0200 From: Philippe Wang User-Agent: Thunderbird 1.5.0.12 (Macintosh/20070509) MIME-Version: 1.0 To: Yitzhak Mandelbaum Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] "opening" record types References: <67ECB685-E69A-43CA-867D-30B879DB0510@research.att.com> In-Reply-To: <67ECB685-E69A-43CA-867D-30B879DB0510@research.att.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Ovh-Remote: 82.227.140.227 (vil93-4-82-227-140-227.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Miltered: at discorde with ID 46CC6504.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; struct:01 sig:01 struct:01 sig:01 cheers:01 yitzhak:01 mandelbaum:01 foo:01 foo:01 cheers:01 yitzhak:01 mandelbaum:01 beginner's:01 ocaml:01 bug:01 Yet another suggestion : Instead of : # module M = struct type t = { a : int ; b : int } end ;; module M : sig type t = { a : int; b : int; } end Write : # module M = struct type t = { a : int ; b : int } module N = struct type t = M.t = { a : int ; b : int } end end ;; module M : sig type t = { a : int; b : int; } module N : sig type t = M.t = { a : int; b : int; } end end Then : # include M.N;; type t = M.t = { a : int; b : int; } So that you can do : # { a = 42 ; b = 23 } ;; - : t = {a = 42; b = 23} That way, when you change or add definitions, it's easy to spread changes, and you export only what you want to export... :-) Cheers, -- Philippe Wang mail[at]philippewang.info Yitzhak Mandelbaum wrote: > Hi, > > I'm generally averse to opening modules, as I find it can make it hard > to figure out where definitions are coming from. Instead, I prefer to > bind only those pieces of the module that I need, and to do so > explicitly. However, there is one instance in which I find myself > with little choice: record types. In order to bind the > field-constructors for a record, you need to copy the entire type from > the module in which its declared. For example, > > module Foo = > struct > type t = {a: int; b:int} > end > > without copying the type: > > let y = {Foo.a=3; Foo.b=4} > > with copying: > > type t = Foo.t = {a: int; b:int} > > let x = {a=3; b=4} > > While this is a nuisance to begin with, its even worse if the record > type is subject to change -- each time it changes, you need to update > every place where you copied the definition. > > Is there any way around this? That is, is there any way to use the > field names of a record defined in another module without opening the > whole module or copying the whole definition of the record. > > Cheers, > Yitzhak > > -------------------------------------------------- > Yitzhak Mandelbaum > AT&T Labs - Research > > http://www.research.att.com/~yitzhak > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >