[
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: | 2006-09-14 (00:01) |
From: | Jacques Garrigue <garrigue@m...> |
Subject: | Re: [Caml-list] Passing class type as parameter? |
From: Jeremy Cowgar <jeremy@cowgar.com> > Can I do something like: > > class base_model = object(self) > method from_array ary = ... > end ;; > > class user = object(self) > inherit base_model > ... > end ;; > > let finder sql class_type = > query_database sql ; > let res = new class_type in > res#from_array res ;; > > let users = finder "SELECT * FROM users" user in > xxx yyy ;; > > Ok. That is not working code, prob has syntax errors as well, but you > get my idea. The problem I am having is passing the class to the > generic finder method. No, you can't, but you can pass the class constructor in place, which is just equivalent. let finder sql class_new = query_database sql ; let res = class_new () in res#from_array res ;; let users = finder "SELECT * FROM users" (fun () -> new user) in xxx yyy ;; Note that in general the class constructor takes arguments, so you don't need the above anonymous function. Jacques Garrigue