caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] [ANNOUNCE] ECaml 0.3 : a simple object system
@ 2004-02-24 14:18 Issac Trotts
  2004-02-25  3:30 ` Jacques Garrigue
  0 siblings, 1 reply; 3+ messages in thread
From: Issac Trotts @ 2004-02-24 14:18 UTC (permalink / raw)
  To: caml-list

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

NEWS:
  o Removed a bug resulting from the use of colon (:) as the method
    invocation operator.  Of course this was conflicting with the type
    casting syntax, so now I am using the operator '#'.  Users can still
    access methods on standard OCaml objects using the word "invoke" in
    place of '#'.
  o Added a way to concisely describe entity types, for module signatures.

-- 
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] [ANNOUNCE] ECaml 0.3 : a simple object system
  2004-02-24 14:18 [Caml-list] [ANNOUNCE] ECaml 0.3 : a simple object system Issac Trotts
@ 2004-02-25  3:30 ` Jacques Garrigue
  2004-02-25  7:59   ` Issac Trotts
  0 siblings, 1 reply; 3+ messages in thread
From: Jacques Garrigue @ 2004-02-25  3:30 UTC (permalink / raw)
  To: ijtrotts; +Cc: caml-list

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.

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>

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.)

Jacques Garrigue

-------------------
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] [ANNOUNCE] ECaml 0.3 : a simple object system
  2004-02-25  3:30 ` Jacques Garrigue
@ 2004-02-25  7:59   ` Issac Trotts
  0 siblings, 0 replies; 3+ messages in thread
From: Issac Trotts @ 2004-02-25  7:59 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-02-25  7:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-24 14:18 [Caml-list] [ANNOUNCE] ECaml 0.3 : a simple object system Issac Trotts
2004-02-25  3:30 ` Jacques Garrigue
2004-02-25  7:59   ` Issac Trotts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).