Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Functors and classes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Prevost <j.prevost@g...>
Subject: Re: [Caml-list] Functors and classes
The following model works for me.  The key problem here is that
there's no way to bring a class binding in in the way you want. 
That's not really a problem, except that you lose the ability to call
"new".  Perhaps the Dbi interface could be changed to allow for this? 
(Depending on how you do things, this could mean that a DbiPool could
itself be used as a Dbi module, somehow.)

It's also possible that I'm missing some way to otherwise do this.

John.


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
    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 () = Thing.connect ()
  end

module X = ThingPool(TestThing)

let x = X.connect ()

let a = x #a
let b = x #b
let c = x #c

-------------------
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