This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

[Caml-announce] G'Caml, Caml with Extensional polymorphism extension
• Jun Furuse
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2001-06-19 (17:26) From: Jun Furuse Subject: [Caml-announce] G'Caml, Caml with Extensional polymorphism extension
```Hello,

I'm pleased to announce G'Caml, the experimental extension of
the extensional polymorphism([1],[2]) to O'Caml, available at

http://pauillac.inria.fr/~furuse/generics/

You can define non parametric, ad-hoc polymorphic values
(so called "overloaded" or "generic" functions)
using newly added "generic" bindings. For example:

# generic plus = case
| int -> int -> int => (+)
| float -> float -> float => (+.)
;;

This defines an ad-hoc polymorphic function plus, which can work
both for integer and float additions.

# plus 1 2;;
- : int = 3

# plus 1.2 3.4;;
- : int = 4.6

Not only such overloaded arithmetic functions, we can define
many interesting ad-hoc polymorphic values which cannot be imagined
in the normal ML.

G'Caml also provides dynamic values and a toplevel magic printing function,
using the internal framework of extensional polymorphism implementation.

We can encapsulate a value and its type into an object typed dyn.
Then using this encapsulated type information, we can perform
run time type checking:

# dyn 1;;
- : dyn = (1 : int)

# coerce (dyn 1) with
| (x : int) => Printf.printf "It is an int %d.\n" x
| (x : float) => Printf.printf "It is a float %f.\n" x
It is an int 1.
- : unit = ()

The toplevel magic printing is the function which many people have
asked for in this list. It can print out any ML value (well, functions
are just printed as <fun>), including the constructor names of
user defined types (this is available only in the toplevel):

# type foo = Foo of int;;

# Toploop.print (Foo 42);;
Foo 42- : unit = ()

G'Caml is still quite experimental and under development.
I am sure that there are tons of bugs.
Do not expect something almost complete,
like the initial O'Labl release...

I hope you could enjoy it.
--
JPF

[1]
"Extensional Polymorphism".
Catherine Dubois, Francois Rouaix, Pierre Weis.
Proceedings POPL 95.
ftp://ftp.inria.fr/INRIA/Projects/cristal/Francois.Rouaix/generics.dvi.Z

[2]
"Generic polymorphism in ML".
Jun Furuse.
Journees Francophones des Langages Applicatifs 2001
http://pauillac.inria.fr/~furuse/publications/jfla2001.ps.gz

```