caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Passing class type as parameter?
@ 2006-09-13 18:58 Jeremy Cowgar
  2006-09-14  0:00 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 2+ messages in thread
From: Jeremy Cowgar @ 2006-09-13 18:58 UTC (permalink / raw)
  To: caml-list

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.

Thanks,

Jeremy


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Passing class type as parameter?
  2006-09-13 18:58 Passing class type as parameter? Jeremy Cowgar
@ 2006-09-14  0:00 ` Jacques Garrigue
  0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2006-09-14  0:00 UTC (permalink / raw)
  To: jeremy; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-09-14  0:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-13 18:58 Passing class type as parameter? Jeremy Cowgar
2006-09-14  0:00 ` [Caml-list] " Jacques Garrigue

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