English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-announce] G'Caml, Caml with Extensional polymorphism extension
[ 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 <Jun.Furuse@i...>
Subject: [Caml-announce] G'Caml, Caml with Extensional polymorphism extension

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


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.

"Extensional Polymorphism".
Catherine Dubois, Francois Rouaix, Pierre Weis. 
Proceedings POPL 95.

"Generic polymorphism in ML".
Jun Furuse.
Journees Francophones des Langages Applicatifs 2001