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 AAA13275; Wed, 4 Aug 2004 00:05:24 +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 AAA12173 for ; Wed, 4 Aug 2004 00:05:23 +0200 (MET DST) Received: from mail3.speakeasy.net (mail3.speakeasy.net [216.254.0.203]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i73M5LmL019102 for ; Wed, 4 Aug 2004 00:05:22 +0200 Received: (qmail 28040 invoked from network); 3 Aug 2004 22:05:20 -0000 Received: from shell2.speakeasy.net ([69.17.110.71]) (envelope-sender ) by mail3.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 3 Aug 2004 22:05:20 -0000 Date: Tue, 3 Aug 2004 15:05:20 -0700 (PDT) From: brogoff To: Ocaml Mailing List Subject: Re: [Caml-list] Functors and classes In-Reply-To: Message-ID: References: <20040803120244.GA22304@annexia.org> <20040803121049.GA22418@annexia.org> <20040803131716.GA22773@annexia.org> <20040803151241.GA25124@annexia.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce with ID 41100C21.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; brogoff:01 brogoff:01 caml-list:01 functors:01 abstraction:01 functors:01 prevost:01 val:01 val:01 struct:01 demonstrate:01 stab:01 caveat:01 struct:01 conn:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Ha, I just tried whipping up an example and I couldn't write a Thing. Oh well, classes/polymorphic variants and the type abstraction features of functors are hard to use together! On Tue, 3 Aug 2004, brogoff wrote: > On Tue, 3 Aug 2004, John Prevost wrote: > > Oops. A couple of errors in that last thing I wrote that weren't the > > problem I was trying to illustrate (that's what I get for trying fixes > > inline before giving up): > > > > module type ThingPoolT = > > sig > > type connection > > val connect : unit -> connection > > val test : connection -> int > > end > > > > module ThingPool (Thing : ThingIntf) : > > (ThingPoolT with type connection = Thing.connection) = > > struct > > type connection = Thing.connection > > let connect () = Thing.connect () > > let test x = x#a + 1 > > end > > Certainly if you're going to call method a it needs to be exposed. If I > understand the problems you're trying to demonstrate, the following would be > my stab at it. Untested code, caveat emptor, blah blah blah... > > module type ThingIntf = > sig > type 'a connection = > 'a constraint 'a = < a: int; connect : unit -> 'a connection; ..> > val connect : unit -> 'a connection > end;; > > module type ThingPoolT = > sig > include ThingIntf > val test : 'a connection -> int > end;; > > module ThingPool (Thing : ThingIntf) : ThingPoolT = > struct > include Thing > > let connect () = > let conn = Thing.connect () in > ignore (conn#a); > conn > > let (test : _ connection -> int) = fun x -> x#a + 1 > end;; > > -- Brian > > ------------------- > 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 > ------------------- 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