From: "Issac Trotts" <ijtrotts@ucdavis.edu>
To: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] [ANNOUNCE] ECaml 0.3 : a simple object system
Date: Tue, 24 Feb 2004 23:59:19 -0800 [thread overview]
Message-ID: <20040225075919.GB1013@manzanita> (raw)
In-Reply-To: <20040225123014F.garrigue@kurims.kyoto-u.ac.jp>
On Wed, Feb 25, 2004 at 12:30:14PM +0900, Jacques Garrigue wrote:
> From: "Issac Trotts" <ijtrotts@ucdavis.edu>
>
> > 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 > = <obj>
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 = <fun>
> # let o = object method m x = x+2 end;;
> val o : < m : int -> int > = <obj>
> # 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 <obj>; `B <obj>]
> # 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 = <fun>
> # 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
prev parent reply other threads:[~2004-02-25 7:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-24 14:18 Issac Trotts
2004-02-25 3:30 ` Jacques Garrigue
2004-02-25 7:59 ` Issac Trotts [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=20040225075919.GB1013@manzanita \
--to=ijtrotts@ucdavis.edu \
--cc=caml-list@inria.fr \
--cc=garrigue@kurims.kyoto-u.ac.jp \
/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