From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA27064; Thu, 22 May 2003 10:31:30 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA27203 for ; Thu, 22 May 2003 10:31:28 +0200 (MET DST) Received: from avalon.ens-lsh.fr (mailhost.ens-lsh.fr [193.51.131.2]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h4M8VQT16015 for ; Thu, 22 May 2003 10:31:28 +0200 (MET DST) Received: from avalon.ens-lsh.fr (localhost [127.0.0.1]) by avalon.ens-lsh.fr (8.12.8/8.12.8) with ESMTP id h4M9UZwC021577 for ; Thu, 22 May 2003 10:30:36 +0100 (WEST) Received: from ens-notes1.ens-lsh.fr (ens-notes1.ens-lsh.fr [10.2.1.44]) by avalon.ens-lsh.fr (8.12.8/8.12.8) with ESMTP id h4M9UZV9021574 for ; Thu, 22 May 2003 10:30:35 +0100 (WEST) Received: from mostha ([10.3.20.3]) by ens-notes1.ens-lsh.fr (Lotus Domino Release 5.0.10) with SMTP id 2003052210312394:26079 ; Thu, 22 May 2003 10:31:23 +0200 Date: Thu, 22 May 2003 10:27:25 +0200 From: Damien To: caml-list@inria.fr Subject: [Caml-list] objects and functions Message-Id: <20030522102725.1631d979.Damien.Pous@ens-lyon.fr> Organization: mosthagloups X-Mailer: Sylpheed version 0.8.11claws141 (GTK+ 1.2.10; i386-debian-linux-gnu) Mime-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on ens-notes1/ENS-LSH(Release 5.0.10 |March 22, 2002) at 22/05/2003 10:31:24, Serialize by Router on ens-notes1/ENS-LSH(Release 5.0.10 |March 22, 2002) at 22/05/2003 10:31:24, Serialize complete at 22/05/2003 10:31:24 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Spam: no; 0.00; damien:01 ens-lyon:01 calc:01 inherit:01 match:02 objects:02 object:03 let:04 parameter:04 efficient:05 functions:05 mod:07 function:09 something:09 nicely:10 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, I would like to create an object whose methods depend on a parameter. the simple way is something like : >class a x = object > method calc = match x with > | 0 -> 0 > | x -> 33 mod x >end a more efficient way (if there are a lot of calc-like methods) would be to test for x before constructing the object : >class a0 = object method calc = 0 end >class ax x = object method calc = 33 mod x end >let fa x = function 0 -> new a0 | x -> new ax x but then I can't nicely inherit from (fa x) :-( so, is there a way (or wouldn't it be useful to have one) for doing something like : >class a = function >| 0 -> object method calc = 0 end >| x -> object method calc = 33 mod x end or >class b x = object > inherit fa x > ... >end thanks, damien ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners