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: | Richard Jones <rich@a...> |
| Subject: | Re: [Caml-list] Functors and classes |
On Tue, Aug 03, 2004 at 11:06:33AM -0400, John Prevost wrote:
I've found a problem with this approach. If I replace the connect
function here:
> module ThingPool (Thing : ThingIntf) :
> (ThingPoolT with type connection = Thing.connection) =
> struct
> type connection = Thing.connection
> let connect () = Thing.connect ()
> end
with:
let connect () =
let conn = Thing.connect () in
ignore (conn#a);
conn
then I get the following error:
File "test.ml", line 30, characters 14-18:
This expression has type Thing.connection
It has no method a
So I extended the type of connection as follows to make it work:
module type ThingIntf =
sig
type connection = <a : int; b : int; c : int>
val connect : unit -> connection
end
That's all well and good. BUT I need to define something more like
this:
module type ThingIntf =
sig
type connection = <a : int; ..>
val connect : unit -> connection
end
which gives me:
File "test.ml", line 14, characters 8-35:
A type variable is unbound in this type declaration
(I'm only uses a small subset of the much larger interface in my
pooling code).
Full code which fails is attached.
Thanks,
Rich.
----------------------------------------------------------------------
module TestThing =
struct
class connection =
object
method a = 1
method b = 1
method c = 1
end
let connect () = new connection
end
module type ThingIntf =
sig
type connection = <a : int; ..>
val connect : unit -> connection
end
module type ThingPoolT =
sig
type connection
val connect : unit -> connection
end
module ThingPool (Thing : ThingIntf) :
(ThingPoolT with type connection = Thing.connection) =
struct
type connection = Thing.connection
let connect () =
let conn = Thing.connect () in
ignore (conn#a);
conn
end
module X = ThingPool(TestThing)
let x = X.connect ()
let a = x #a
let b = x #b
let c = x #c
----------------------------------------------------------------------
--
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
If I have not seen as far as others, it is because I have been
standing in the footprints of giants. -- from Usenet
-------------------
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