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 PAA32079; Wed, 4 Feb 2004 15:45:32 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA32074 for ; Wed, 4 Feb 2004 15:45:31 +0100 (MET) Received: from bernache.ens-lyon.fr (bernache.ens-lyon.fr [140.77.167.10]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id i14EjUP13628 for ; Wed, 4 Feb 2004 15:45:30 +0100 (MET) Received: by bernache.ens-lyon.fr (Postfix, from userid 103) id E09F17ACB9F; Wed, 4 Feb 2004 13:08:27 +0100 (CET) Received: from mouette.ens-lyon.fr (mouette.ens-lyon.fr [140.77.167.4]) by bernache.ens-lyon.fr (Postfix) with ESMTP id F32237AC3FE for ; Wed, 4 Feb 2004 13:01:41 +0100 (CET) Received: from www-data by mouette.ens-lyon.fr with local (Exim 3.35 #1 (Debian)) id 1Ao77p-0007Rp-00 for ; Tue, 03 Feb 2004 21:26:25 +0100 To: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] functors and objects' Message-ID: <1075839985.402003f1527cb@mouette.ens-lyon.fr> Date: Tue, 03 Feb 2004 21:26:25 +0100 (CET) From: Damien Pous References: <20040203190635.6cc61ff0.Damien.Pous@ens-lyon.fr> <20040203193958.GA9048@swordfish> In-Reply-To: <20040203193958.GA9048@swordfish> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: IMP/PHP IMAP webmail program 2.2.6 X-Originating-IP: 193.51.131.2 X-Spam-Status: No, hits=-1.9 required=5.0 tests=DATE_IN_PAST_12_24,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, REPLY_WITH_QUOTES,USER_AGENT version=2.55 X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp) X-Spam-Report: ---- Start SpamAssassin results -1.90 points, 5 required; * -0.5 -- Has a valid-looking References header * -0.5 -- Has a In-Reply-To header * -0.5 -- BODY: Contains what looks like a quoted email text * 0.1 -- Date: is 12 to 24 hours before Received: date * -0.5 -- Reply with quoted text * 0.0 -- Has a User-Agent header ---- End of SpamAssassin results X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 functors:01 damien:01 damien:01 ens-lyon:01 gushee:01 mgushee:01 havenrock:01 2004:99 sigh:01 casts:01 functor:01 struct:01 val:01 struct:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk En réponse à Matt Gushee : > On Tue, Feb 03, 2004 at 07:06:35PM +0100, Damien wrote: > > type t :> o (* sigh... *) > > The first problem is that you're mixing type declarations and class > casts ... not a hard mistake to make, since the class cast syntax is a > bit confusing, and doesn't seem to be explained very well anywhere. of course, this was not "real OCaml code" :) I just wanted to express the fact that my functor R has to accept any module M defining an object type `t' with at least a method `react' (that is, t :> o) > > module R(M: O') = > > struct > > include R(M) > > I don't see how this can work, because this module R takes an argument > of type O', whereas the other R (do you really want to give them the > same name?) takes an argument of type O. Regardless of their contents, > they are different interfaces and thus not interchangeable. since o' :> o, M: O' should be a valid candidate for R... > There's undoubtedly a way to achieve the result you want, but I don't > really understand what you are trying to do. the following correct code does partially what I want : module type O = sig type t val send: [<`React] -> t -> unit end module R(M: O) = struct let l = ref [] let register (o: M.t) = l := o :: !l let react() = List.iter (M.send `React) !l end module type O' = sig type t val send: [<`React|`Render] -> t -> unit end module R'(M: O') = struct include R(M) (* <-- "subtyping" is automagically done *) let render() = List.iter (M.send `Render) !l end but I am partially re-encoding objects with modules and variants, and this encoding becomes quite ugly when it comes to _real_ objects (with inheritance, virtual methods...) > Do you actually have a specific goal in mind, or are you just experimenting? both ! I am working on a project that use a "Reactor" where a lots of "Objects" react. This project is cut into three layers : Base reactor and objects (generic) Meaningful reactor and objects (objects really react) Rendered reactor and objects (Gtk, maybe GL some day) Currently both reactor and objects are "OCaml objects", but the project only use _one_ instance of the rendered reactor class. Thus I am wondering how I could turn it into a module... This module has to be defined incrementally : Base, Meaningful, Rendered. but at the Base level, the final type of contained objects is unknown, whence the need for a functor. (with objects, this is done with parametrized classes) Since objects really need to be "objects" (late binding), I cannot turn both objects and reactor into modules (or at least in a beautiful way) arf... damien ------------------- 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