Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Leo P White <lpw25@cam.ac.uk>
To: caml <caml-list@inria.fr>
Subject: [Caml-list] Proposal for extensible open datatypes
Date: 06 Jan 2012 00:32:07 +0000	[thread overview]
Message-ID: <Prayer.1.3.4.1201060032070.9235@hermes-2.csi.cam.ac.uk> (raw)

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


             reply	other threads:[~2012-01-06  0:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-06  0:32 Leo P White [this message]
2012-01-06  6:26 ` Andrej Bauer
2012-01-06  8:56   ` Andreas Rossberg
2012-01-06  9:24     ` Leo P White

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Prayer.1.3.4.1201060032070.9235@hermes-2.csi.cam.ac.uk \
    --to=lpw25@cam.ac.uk \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox