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=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 503B4BBAF for ; Mon, 20 Apr 2009 07:23:24 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtEBAAyk60nZSMDqi2dsb2JhbACBTpRtAQEBCgsKBw8FtESDfQY X-IronPort-AV: E=Sophos;i="4.38,431,1233529200"; d="scan'208";a="27940336" Received: from fmmailgate03.web.de ([217.72.192.234]) by mail1-smtp-roc.national.inria.fr with ESMTP; 20 Apr 2009 07:23:24 +0200 Received: from smtp06.web.de (fmsmtp06.dlan.cinetic.de [172.20.5.172]) by fmmailgate03.web.de (Postfix) with ESMTP id 96852FAC945B; Mon, 20 Apr 2009 07:23:23 +0200 (CEST) Received: from [78.43.226.218] (helo=frosties.localdomain) by smtp06.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #277) id 1LvlyV-00089S-00; Mon, 20 Apr 2009 07:23:23 +0200 Received: from mrvn by frosties.localdomain with local (Exim 4.69) (envelope-from ) id 1LvlyU-0005XI-OF; Mon, 20 Apr 2009 07:23:22 +0200 From: Goswin von Brederlow To: Martin Jambon Cc: Ashish Agarwal , caml-list@yquem.inria.fr Subject: Re: [Caml-list] Extending modules and signatures References: <49E9E195.6030603@ens-lyon.org> <49EBBC6C.8000502@ens-lyon.org> Date: Mon, 20 Apr 2009 07:23:22 +0200 In-Reply-To: <49EBBC6C.8000502@ens-lyon.org> (Martin Jambon's message of "Mon, 20 Apr 2009 02:06:04 +0200") Message-ID: <873ac3x5it.fsf@frosties.localdomain> User-Agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.4.21 (linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX19DI33D0S4lx7fm0u1AES6CtBZ9x9+Oocsgl1z1 Jykz8pw4BiU5M81EtNLPShMKZDdZlnW50Qjn/VYoPEqklDatOx aP+BCsHYA= X-Spam: no; 0.00; ens-lyon:01 module's:01 functor:01 sig:01 val:01 struct:01 struct:01 ocaml:01 mfg:98 signatures:01 signatures:01 caml-list:01 inherit:01 int:01 int:01 Martin Jambon writes: > OK, but I think the real issue is inheritance. In order to truly extend an > existing module, one needs to access the private items of the inherited module > implementation. In order to avoid messing up with the original module's > global variables, the inherited "module" should be more like a functor that > would create a fresh instance of the module each time it is instantiated, just > like classes generate objects. > > > I could imagine something like this: > > module class A : > sig > val get_x : unit -> int > end = > struct > let x = ref 123 > let get_x () = !x > end > > module class B = > struct > inherit A > let incr_x () = incr x > end > > module B1 = new module B > module B2 = new module B > ;; > > B1.incr_x ();; > - : unit = () > B1.get_x ();; > - : int = 124 > B2.get_x ();; > - : int = 123 > > > Module class implementations and signatures could be conveniently created as > whole files using new file extensions, say .mc and .mci. These would be like > .ml files except that they would support module class inheritance and would be > evaluated only when they are instantiated with "new module". Which would also need module A1 = new module A module A2 = new module A A1.incr_x () A1.get_x;; - : int = 124 A2.get_x ();; - : int = 123 So you see A does not have global variables but only instance variables. What you describe are ocaml objects. Not modules. MfG Goswin