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 IAA24136; Wed, 25 Feb 2004 08:59:39 +0100 (MET) 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 IAA22130 for ; Wed, 25 Feb 2004 08:59:38 +0100 (MET) Received: from pop19.ucdavis.edu (pop19.ucdavis.edu [169.237.105.29]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i1P7xcIq030750 for ; Wed, 25 Feb 2004 08:59:39 +0100 Received: from manzanita ([128.120.141.214]) by pop19.ucdavis.edu (8.12.10/8.12.9/it-std-5.2.0) with SMTP id i1P7xY4U019712; Tue, 24 Feb 2004 23:59:34 -0800 (PST) Received: by manzanita (sSMTP sendmail emulation); Tue, 24 Feb 2004 23:59:19 +4000 From: "Issac Trotts" Date: Tue, 24 Feb 2004 23:59:19 -0800 To: Jacques Garrigue Cc: caml-list@inria.fr Subject: Re: [Caml-list] [ANNOUNCE] ECaml 0.3 : a simple object system Message-ID: <20040225075919.GB1013@manzanita> Mail-Followup-To: ijtrotts@ucdavis.edu, Jacques Garrigue , caml-list@inria.fr References: <20040224141811.GA4398@manzanita> <20040225123014F.garrigue@kurims.kyoto-u.ac.jp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040225123014F.garrigue@kurims.kyoto-u.ac.jp> User-Agent: Mutt/1.5.4i X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; issac:01 trotts:01 ijtrotts:01 caml-list:01 2004:99 0900,:01 jacques:01 issac:01 trotts:01 ijtrotts:01 camlp:01 3.07:01 2004:99 val:01 3.07:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, Feb 25, 2004 at 12:30:14PM +0900, Jacques Garrigue wrote: > From: "Issac Trotts" > > > ECaml is a simple object system for OCaml, based on polymorphic variants > > and a Camlp4 syntax extension. > > > > ECaml can > > o create objects (entities) of anonymous class > > o create new classes within functions or other classes. > > o very easily define methods having polymorphic arguments > > Interesting. > I shall have a look at your encoding. It would be good to get your feedback on it. > You may also be interested by having a look at the current CVS version > of objective caml, because it actually has all the features you > describe. (This doesn't reduce your merit.) > Just a one line example: > Objective Caml version 3.07+13 (2004-01-04) > > # let o = object method id x = x end;; > val o : < id : 'a -> 'a > = This is very good to see. As far as I can tell, the OCaml object system can now do everything that ECaml can do. The only reason to use ECaml now would be if you are using an older version of OCaml (pre 3.07+13), or just to see an example of something fun to do with polymorphic variants and Camlp4. > And if you like experiments, you may even try the objvariants branch. > Just get the CVS version, and then do: > cvs update -r objvariants typing > It allows you to use unions of object types. > This is a quick hack (2 hours coding), and there may be bugs, but it > can be funny. Here is an example session. > > # let f (x : [> ]) = x#m 3;; > val f : [> as < m : int -> 'a; .. > ] -> 'a = > # let o = object method m x = x+2 end;; > val o : < m : int -> int > = > # f (`A o);; > - : int = 5 > # let l = [`A o; `B(object method m x = x -2 method y = 3 end)];; > val l : > [> `A of < m : int -> int > | `B of < m : int -> int; y : int > ] list = > [`A ; `B ] > # List.map f l;; > - : int list = [5; 1] > # let g = function `A x -> x#m 3 | `B x -> x#y;; > val g : [< `A of < m : int -> 'a; .. > | `B of < y : 'a; .. > ] -> 'a = > # List.map g l;; > - : int list = [5; 3] > > The type annotation (x : [> ]) is necessary: # is actually overloaded > on objects (the default) and variants of objects. You can view the > variant tag here a bit like a runtime type: you can pattern-match on > it when needed, but you can also call a method common to all cases > without looking at the tag. > > I got the idea in a paper (in Japanese) by Hideshi Nagira and Atsushi > Igarashi, but actually this trick was first suggested to me by Koji > Kagawa about 5 years ago. > > (Disclaimer: this kind of experiment is for fun, don't expect it in > the main branch anytime soon or ever.) I like it. Thanks for your message. -- Issac Trotts http://redwood.ucdavis.edu/~issac ------------------- 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