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 SAA00629; Tue, 3 Aug 2004 18:42:32 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA01207 for ; Tue, 3 Aug 2004 18:42:31 +0200 (MET DST) Received: from annexia.force9.co.uk (annexia.force9.co.uk [212.56.101.183]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i73GgUSH022294 for ; Tue, 3 Aug 2004 18:42:30 +0200 Received: from rich by annexia.force9.co.uk with local (Exim 3.36 #1 (Debian)) id 1Bs2Mv-0006wQ-00; Tue, 03 Aug 2004 17:42:29 +0100 Date: Tue, 3 Aug 2004 17:42:29 +0100 To: John Prevost Cc: Ocaml Mailing List Subject: Re: [Caml-list] Functors and classes Message-ID: <20040803164229.GA26451@annexia.org> References: <20040803120244.GA22304@annexia.org> <20040803121049.GA22418@annexia.org> <20040803131716.GA22773@annexia.org> <20040803155026.GB25124@annexia.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.5.1+cvs20040105i From: Richard Jones X-Miltered: at concorde with ID 410FC076.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 functors:01 2004:99 0400,:01 prevost:01 functors:01 non-obvious:01 dbi:99 api:01 functor:01 dbi:99 postgres:01 dbh:99 dbh:99 functor:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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