caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: jeremy@cowgar.com
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Passing class type as parameter?
Date: Thu, 14 Sep 2006 09:00:40 +0900 (JST)	[thread overview]
Message-ID: <20060914.090040.92346078.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <D2466E0B-332C-4733-82AF-DF701C5C97AE@cowgar.com>

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


      reply	other threads:[~2006-09-14  0:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-13 18:58 Jeremy Cowgar
2006-09-14  0:00 ` Jacques Garrigue [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060914.090040.92346078.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@yquem.inria.fr \
    --cc=jeremy@cowgar.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).