From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA07991; Wed, 23 Apr 2003 16:52:23 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA07835 for ; Wed, 23 Apr 2003 16:52:22 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from h00045a4799d6.ne.client2.attbi.com (h00045a4799d6.ne.client2.attbi.com [65.96.179.155]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h3NEqLT13525 for ; Wed, 23 Apr 2003 16:52:21 +0200 (MET DST) Received: by h00045a4799d6.ne.client2.attbi.com (Postfix, from userid 500) id 54CFA2BB74; Wed, 23 Apr 2003 10:56:51 -0400 (EDT) From: Neel Krishnaswami MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16038.43443.192953.705022@h00045a4799d6.ne.client2.attbi.com> Date: Wed, 23 Apr 2003 10:56:51 -0400 To: caml-list@inria.fr Subject: Re: [Caml-list] Yelling In-Reply-To: <200304231716.23923.exa@kablonet.com.tr> References: <200304231716.23923.exa@kablonet.com.tr> X-Mailer: VM 7.04 under 21.4 (patch 8) "Honest Recruiter" XEmacs Lucid X-Spam: no; 0.00; neel:01 krishnaswami:01 neelk:01 caml-list:01 eray:01 ozkural:01 subtyping:01 foo:01 foo's:01 val:01 tolerable:01 struct:01 intermix:01 compiler:01 bindings:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Eray Ozkural writes: > > BTW, does somebody have a good idea of how to make one module > inherit from another? Say, for implementing Graph using > Digraph. It's too bad there isn't an Ada like package extension > mechanism. You can pretty easily simulate the effect of this kind of inheritance using the module system, but it's a moderate pain. First, I'll talk about module signatures. Signatures have a structural subtyping relationship -- signature BAR is a subtype of FOO if it supports all of FOO's interface. It is permitted to offer more operations, but must include all of FOO's types and values. Then you can use a module of signature BAR wherever a FOO is expected. Here's an example: module type FOO = sig type t val v : t end module type BAR = (* This is a subtype of FOO *) sig type t val v : t val v' : t end Notice that there's no syntax to abbreviate the definition of BAR; you need to manually include all of the types and operations in it. This will be your main annoyance, but for a closed library it's tolerable. Happily, there is syntax to abbreviate the *implementation* of module extensions. You can implement one module, and then use the include keyword to add its types and bindings to some other module. For example: module Foo : FOO = struct type t = Foo of unit let v = Foo() end module Bar : BAR with type t = Foo.t = struct include Foo (* Add the type t and value v to the Foo module *) let v' = v end The "with type t = Foo.t" thing at the top of Bar is a sharing declaration. It informs the compiler that the type Bar.t is the same as the type Foo.t, so you can freely intermix Foo.t and Bar.t values. (Otherwise the compiler would forbid it, on the grounds that these are two different abstract types.) I hope this helps! -- Neel Krishnaswami neelk@alum.mit.edu ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners