Browse thread
[Caml-list] Functors and classes
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | brogoff <brogoff@s...> |
| Subject: | Re: [Caml-list] Functors and classes |
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