caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Proposal for extensible open datatypes
@ 2012-01-06  0:32 Leo P White
  2012-01-06  6:26 ` Andrej Bauer
  0 siblings, 1 reply; 4+ messages in thread
From: Leo P White @ 2012-01-06  0:32 UTC (permalink / raw)
  To: caml

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


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

end of thread, other threads:[~2012-01-06  9:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-06  0:32 [Caml-list] Proposal for extensible open datatypes Leo P White
2012-01-06  6:26 ` Andrej Bauer
2012-01-06  8:56   ` Andreas Rossberg
2012-01-06  9:24     ` Leo P White

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