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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 40496BBC4 for ; Fri, 17 Apr 2009 23:36:37 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoYDAFuT6EnZSMDqi2dsb2JhbACBTpRrAQEBCgsKBw8FuHWDfQaHYQ X-IronPort-AV: E=Sophos;i="4.40,206,1238968800"; d="scan'208";a="26425084" Received: from fmmailgate03.web.de ([217.72.192.234]) by mail3-smtp-sop.national.inria.fr with ESMTP; 17 Apr 2009 23:36:36 +0200 Received: from smtp05.web.de (fmsmtp05.dlan.cinetic.de [172.20.4.166]) by fmmailgate03.web.de (Postfix) with ESMTP id 50BF7FAA40BD; Fri, 17 Apr 2009 23:36:36 +0200 (CEST) Received: from [78.43.226.218] (helo=frosties.localdomain) by smtp05.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #277) id 1Luvjg-0006EM-00; Fri, 17 Apr 2009 23:36:36 +0200 Received: from mrvn by frosties.localdomain with local (Exim 4.69) (envelope-from ) id 1Luvjf-0004fi-Q0; Fri, 17 Apr 2009 23:36:35 +0200 From: Goswin von Brederlow To: Peter Hawkins Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Extending modules and signatures References: Date: Fri, 17 Apr 2009 23:36:35 +0200 In-Reply-To: (Peter Hawkins's message of "Fri, 17 Apr 2009 13:51:45 -0700") Message-ID: <87ocuv2c9o.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: V01U2FsdGVkX1+4h9VOqFYbaDjcB/Qws43To+BCyCb/SkSGVQ07 E7Y0jCW/gUHwB8XnoIpSo6teSi2iQY2zvmvRfJrusMfhLJYmxp 85l8M/J7w= X-Spam: no; 0.00; mylist:01 struct:01 foo:01 mli:01 mli:01 mylist:01 sig:01 val:01 foo:01 val:01 struct:01 sig:01 cheers:01 mfg:98 ideally:01 Peter Hawkins writes: > Hi... > > I have a quick question. I want to extend the List module with various > functions that I want that aren't present in the standard library, > much as the Batteries ExtList library does. > > I might write the following code in "mylibrary.ml": > module MyList = struct > include List > let foo x = ... code here > let bar y = ... code here > end > > That's ok so far, but now suppose I want to write a "mylibrary.mli" > interface file corresponding to "mylibrary.ml". Ideally I'd write > something like this in "mylibrary.mli": > module MyList : sig > include List (* unknown module type List *) > val foo : ... > val bar : ... > end > > Unfortunately I can't include "List" here since it is a structure, not > a signature. I don't think there is a way to say "include the > signature associated with List". > > I can think of three solutions: > a) Copy the complete signature of List into MyList. This is a bad idea > since the List module might change in the future. This is what the > Batteries ExtList module does. > b) Alter the List module to define a signature, say List.S, in > addition to its other contents. I can't easily do this since I didn't > write the List module. > c) Don't write a .mli file at all. > > Are there any other alternatives? Something like : module MyList = struct include List module M : sig val foo : int -> unit end = struct let foo x = () let bar y = y end include M end and no .mli file. The module M is there to alow you to give (or hide) the signature of just your extra functions. > Cheers, > Peter MfG Goswin