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.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id CD5FABBC1 for ; Wed, 30 Apr 2008 02:06:03 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAE5UF0iCNhAB/2dsb2JhbACtDw X-IronPort-AV: E=Sophos;i="4.25,725,1199660400"; d="scan'208";a="11655443" Received: from kurims.kurims.kyoto-u.ac.jp ([130.54.16.1]) by mail1-smtp-roc.national.inria.fr with ESMTP; 30 Apr 2008 02:06:02 +0200 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.8/8.13.8) with ESMTP id m3U05p7p007527; Wed, 30 Apr 2008 09:05:52 +0900 (JST) Date: Wed, 30 Apr 2008 09:05:41 +0900 (JST) Message-Id: <20080430.090541.77051652.garrigue@math.nagoya-u.ac.jp> To: ecc@cmu.edu Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Invoking the standard library ? From: Jacques Garrigue In-Reply-To: <20080429181958.GB18818@stratocaster.home> References: <1209479205.11285.15.camel@Blefuscu> <20080429181958.GB18818@stratocaster.home> X-Mailer: Mew version 4.2 on Emacs 22.1 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; 0200,:01 bindings:01 toplevel:01 struct:01 compiler:01 struct:01 bug:01 ocaml's:01 compiler:01 listlabels:01 stdlabels:01 stdlabels:01 unbound:01 wrote:01 compile:01 From: Eric Cooper Subject: Re: [Caml-list] Invoking the standard library ? Date: Tue, 29 Apr 2008 14:19:58 -0400 > On Tue, Apr 29, 2008 at 04:26:45PM +0200, David Teller wrote: > > modules String, Stream, etc. For this, I need to include the original > > module, as provided in the standard library, and add stuff. Now, the > > trick is that I'd like to keep the same name as the original module. > > My first thought was that the usual shadowing of bindings could > be used, and indeed the following works fine in the toplevel: > > module String = > struct > include String > let my_extension = ... > end > > But when I tried to compile it separately (just > include String > let my_extension = ... > in a file "string.ml"), I got an error "Unbound module String". > > I don't understand why the behavior is different in these two cases; > apparently the batch compiler binds String as soon as it starts compiling > "string.ml", whereas the top-level does so only after compiling the > struct body. Is this a bug? This is a limitation of ocaml's mapping between file names and modules: a program cannot contain two files with the same name. Even if you somehow succeed in doing so by tricking the compiler, you're on your way for lots of trouble. So the answer is that the new string module should be in a file with a different name. This is actually what is done in the distribution for labelled versions of standard library modules: they are first defined with different names (ListLabels, ...), and then wrapper modules are defined containing them with standard names (StdLabels). Of course once you've done "open StdLabels" there is no way to access the original List module (except if you've first defined an alias for it with a different name). It has been discussed at times that putting the standard library in a packed module would alleviate this problem. However, this would make it monolithic, meaning that all programs would have to include all the standard library. Regards, Jacques Garrigue