From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id DF7C6BB83 for ; Thu, 14 Sep 2006 02:01:06 +0200 (CEST) Received: from rabbit.math.nagoya-u.ac.jp (rabbit.math.nagoya-u.ac.jp [133.6.130.5]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k8E01467016790 for ; Thu, 14 Sep 2006 02:01:06 +0200 Received: from localhost (moose-172 [172.16.254.3]) by rabbit.math.nagoya-u.ac.jp (8.12.11/3.7W) with ESMTP id k8E00fs6013461; Thu, 14 Sep 2006 09:00:41 +0900 (JST) Date: Thu, 14 Sep 2006 09:00:40 +0900 (JST) Message-Id: <20060914.090040.92346078.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? From: Jacques Garrigue In-Reply-To: References: X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 45089BC0.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; model:01 model:01 syntax:01 finder:98 finder:98 caml-list:01 constructor:01 constructor:01 inherit:01 parameter:02 garrigue:03 garrigue:03 jacques:03 jacques:03 let:03 From: Jeremy Cowgar > 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