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 RAA09878; Thu, 22 May 2003 17:04:44 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA10058 for ; Thu, 22 May 2003 17:04:43 +0200 (MET DST) Received: from avalon.ens-lsh.fr (mailhost.ens-lsh.fr [193.51.131.2]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h4MF4gH09285 for ; Thu, 22 May 2003 17:04:42 +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 h4MG3qmC000603 for ; Thu, 22 May 2003 17:03:52 +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 h4MG3qV9000600 for ; Thu, 22 May 2003 17:03:52 +0100 (WEST) Received: from mostha ([10.3.20.3]) by ens-notes1.ens-lsh.fr (Lotus Domino Release 5.0.10) with SMTP id 2003052217044005:27587 ; Thu, 22 May 2003 17:04:40 +0200 Date: Thu, 22 May 2003 17:00:31 +0200 From: Damien To: caml-list@inria.fr Subject: Re: [Caml-list] objects and functions Message-Id: <20030522170031.7ac934d5.Damien.Pous@ens-lyon.fr> In-Reply-To: <20030522.160012.37048456.debian00@tiscali.be> References: <20030522102725.1631d979.Damien.Pous@ens-lyon.fr> <20030522.160012.37048456.debian00@tiscali.be> 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 17:04:40, Serialize by Router on ens-notes1/ENS-LSH(Release 5.0.10 |March 22, 2002) at 22/05/2003 17:04:40, Serialize complete at 22/05/2003 17:04:40 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Spam: no; 0.00; damien:01 ens-lyon:01 caml-list:01 troestler:01 calc:01 read-only:01 compiler:01 unify:01 christophe:01 inherit:01 readable:01 match:02 modules:02 rewritten:02 objects:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 22 May 2003 16:00:12 +0200 (CEST) Christophe TROESTLER wrote: > What about: > > class a x = > let x = match x with 0 -> 0 | x -> 33 mod x in > object > method calc = x > end;; > > class b x = > object > inherit (a x) > end;; Laurent Vibert answered me the same thing... I've simplified too much :( I meant >class a x = object > method calc y = match x with > | 0 -> 0 > | x -> y mod x >end that can be rewritten >class a x = >let f = match x with > | 0 -> fun _ -> 0 > | x -> fun y -> y mod x >in > object method calc = f >end this works pretty well while there is only a few calc-like methods, if not the code becomes less readable. In fact I was more interested by the question of seeing objects as _real_ first class values. Laurent Vibert answered to me this had been studied but that it complicates the compiler too much with respect to the benefits brought. the other case it could be handy is when you want to "unify" two objects that are quite complex (thus with "read-only" implementation) : >class type t = (* something dealing with a dozen modules *) >class a: t >class b: t > >class ab = function >| `A -> a >| `B -> b >class c x = object > inherit ab x > ... >end I found this nice :) 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