From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q060WDTL009565 for ; Fri, 6 Jan 2012 01:32:13 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuUBAK9ABk+DbwiXmWdsb2JhbABCggWqfCIBAQEBAQgLCwcUJYIgEVKBLYgPBpZTn0iMEQSaVYxm X-IronPort-AV: E=Sophos;i="4.71,464,1320620400"; d="scan'208";a="138057173" Received: from ppsw-51.csi.cam.ac.uk ([131.111.8.151]) by mail1-smtp-roc.national.inria.fr with ESMTP; 06 Jan 2012 01:32:08 +0100 X-Cam-AntiVirus: no malware found X-Cam-SpamDetails: not scanned X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Received: from hermes-2.csi.cam.ac.uk ([131.111.8.54]:45897) by ppsw-51.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.158]:25) with esmtpa (EXTERNAL:lpw25) id 1Rixj5-0003RZ-YL (Exim 4.72) for caml-list@inria.fr (return-path ); Fri, 06 Jan 2012 00:32:07 +0000 Received: from prayer by hermes-2.csi.cam.ac.uk (hermes.cam.ac.uk) with local (PRAYER:lpw25) id 1Rixj5-0005dQ-HY (Exim 4.67) for caml-list@inria.fr (return-path ); Fri, 06 Jan 2012 00:32:07 +0000 Received: from [86.22.78.1] by webmail.hermes.cam.ac.uk with HTTP (Prayer-1.3.4); 06 Jan 2012 00:32:07 +0000 Date: 06 Jan 2012 00:32:07 +0000 From: Leo P White To: caml Message-ID: X-Mailer: Prayer v1.3.4 Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=ISO-8859-1 Sender: "L.P. White" Subject: [Caml-list] Proposal for extensible open datatypes 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