Google Groups Home
Help | Sign in
Passing class type as parameter?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Jeremy Cowgar  
View profile
 More options Sep 13 2006, 3:00 pm
Newsgroups: fa.caml
From: Jeremy Cowgar <jer...@cowgar.com>
Date: Wed, 13 Sep 2006 19:00:42 UTC
Local: Wed, Sep 13 2006 3:00 pm
Subject: [Caml-list] Passing class type as parameter?
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

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacques Garrigue  
View profile
 More options Sep 13 2006, 8:04 pm
Newsgroups: fa.caml
From: Jacques Garrigue <garri...@math.nagoya-u.ac.jp>
Date: Thu, 14 Sep 2006 00:04:26 UTC
Local: Wed, Sep 13 2006 8:04 pm
Subject: Re: [Caml-list] Passing class type as parameter?
From: Jeremy Cowgar <jer...@cowgar.com>

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

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google