From: Richard Jones <rich@annexia.org>
To: John Prevost <j.prevost@gmail.com>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Functors and classes
Date: Tue, 3 Aug 2004 16:50:27 +0100 [thread overview]
Message-ID: <20040803155026.GB25124@annexia.org> (raw)
In-Reply-To: <d849ad2a04080308062629fb25@mail.gmail.com>
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
next prev parent reply other threads:[~2004-08-03 15:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-03 12:02 Richard Jones
2004-08-03 12:10 ` Richard Jones
2004-08-03 13:17 ` Richard Jones
2004-08-03 15:06 ` John Prevost
2004-08-03 15:12 ` Richard Jones
2004-08-03 15:27 ` John Prevost
2004-08-03 15:28 ` John Prevost
2004-08-03 19:57 ` brogoff
2004-08-03 22:05 ` brogoff
2004-08-03 23:24 ` John Prevost
2004-08-03 15:50 ` Richard Jones [this message]
2004-08-03 16:23 ` John Prevost
2004-08-03 16:42 ` Richard Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040803155026.GB25124@annexia.org \
--to=rich@annexia.org \
--cc=caml-list@inria.fr \
--cc=j.prevost@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).