Hi all,

I have made a small extension to OCaml to allow open datatypes (like exn) to be created by the programmer. A patch and more details are available at http://sites.google.com/site/ocamlopen/.

The basic syntax is:

 open type foo

 open type 'a bar

 extend foo with Foo1 of int

 extend foo with Foo2 of string

 extend 'a bar with Bar of int * 'a


Open GADTs can also be created (with two possible syntaxes):

 open type 'a gadt

 extend 'a gadt with A : int -> int gadt

 extend string gadt with B of string


Although open types are in some ways similar to polymorphic variants, they are more similar to ordinary variants:

* Constructors for open types can be used anywhere that an ordinary variant
     constructor can be used.

* Constructors for open types have a single type, which can make them less
     prone to errors than polymorphic variants

* Constructors for open types are associated with modules, so they can be
     hidden by signatures.

   * Open types can be Generalized Abstract Data Types

My original motivation for this was wanting to allow arbitrary data to be attached onto various points of a very large data structure (an AST). This can be done using local exceptions, but I wanted these values to have their own type. I think it might also be useful, when using GADTs to represent types, to allow these representations to be extended for user defined types.

Regards,

Leo


--
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to