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 12:23:07PM -0400, John Prevost wrote:
> Yes, that's the same problem I'm seeing. I think it *might* be
> possible to get around it by using a connection type with type
> parameters. Maybe. I'll investigate more in a few hours.
>
> This is an upsetting problem, but I believe that it's known that there
> are some drawbacks to mixing classes and functors. (And, well, if
> it's not, it should be now.) Anyway, we'll see what can be done.
>
> If one of the approaches I'm thinking of would work, it might either
> suggest a rather painful (and non-obvious) change to the Dbi API, or
> it might be possible to define a functor or simple wrapper to turn a
> Dbi module into a Dbi' module that works well for this.
>
> And maybe someone who's done a lot of work with classes and modules
> will mention a really nifty solution. :)
One "solution" I've come up with is to add a functional interface to
Dbi_postgres. ie: adding this to the end:
let connect ?host ?port ?user ?password database =
new connection ?host ?port ?user ?password database
let close (dbh : connection) = dbh#close ()
let closed (dbh : connection) = dbh#closed
let commit (dbh : connection) = dbh#commit ()
let ping (dbh : connection) = dbh#ping ()
let rollback (dbh : connection) = dbh#rollback ()
then I've changed the functor input signature to:
module type DbiDriverT = sig
type connection
val connect : ?host:string -> ?port:string ->
?user:string -> ?password:string -> string ->
connection
val close : connection -> unit
val closed : connection -> bool
val commit : connection -> unit
val ping : connection -> bool
val rollback : connection -> unit
end
with appropriate changes to the functor itself to use the functions
instead of methods.
It works, but it's not particularly elegant, and a better solution
would be welcome.
Rich.
--
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
'There is a joke about American engineers and French engineers. The
American team brings a prototype to the French team. The French team's
response is: "Well, it works fine in practice; but how will it hold up
in theory?"'
-------------------
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