From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q3BLDFUS030275 for ; Wed, 11 Apr 2012 23:13:15 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuEBAGrzhU+DbwiWmWdsb2JhbAAqGrlWIgEBAQEBCAsLBxQngjcRUoEtiCEEBymZEZg/iQmRdQSWfYRhjSw X-IronPort-AV: E=Sophos;i="4.75,406,1330902000"; d="scan'208";a="139880245" Received: from ppsw-50.csi.cam.ac.uk ([131.111.8.150]) by mail4-smtp-sop.national.inria.fr with ESMTP; 11 Apr 2012 23:13:10 +0200 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]:46830) by ppsw-50.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.157]:25) with esmtpa (EXTERNAL:lpw25) id 1SI4qj-0001Uq-sJ (Exim 4.72) for caml-list@inria.fr (return-path ); Wed, 11 Apr 2012 22:13:09 +0100 Received: from prayer by hermes-2.csi.cam.ac.uk (hermes.cam.ac.uk) with local (PRAYER:lpw25) id 1SI4qj-0001bR-P5 (Exim 4.67) for caml-list@inria.fr (return-path ); Wed, 11 Apr 2012 22:13:09 +0100 Received: from [86.26.0.34] by webmail.hermes.cam.ac.uk with HTTP (Prayer-1.3.4); 11 Apr 2012 22:13:09 +0100 Date: 11 Apr 2012 22:13:09 +0100 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] [ANN] ocamlopen 1.0.2 Hi, If anyone is interested, I have written a new version of my patch to add open extensible types to OCaml. It is available at: https://sites.google.com/site/ocamlopen/ The only new feature is allowing variant declarations to be made extensible. This allows declarations like: open type foo = A | B of int | .. Having implemented it, I think that the extension might well be better off without this feature, so I am also releasing another version of the patch without it. I have also written a much better example of how open types and GADTs might be used. It basically shows how classes can be created that permit a kind of nominative down-casting. I have included it below. Finally, I have also added a feature request to Mantis if anyone would like to comment. http://caml.inria.fr/mantis/view.php?id=5584 Regards, Leo -------------------------------- open type 'a class_name exception Bad_cast class type castable = object method cast: 'a.'a class_name -> 'a end (* Lets create a castable class with a name*) class type foo_t = object inherit castable method foo: string end extend 'a class_name with Foo: foo_t class_name class foo: foo_t = object(self) method cast: type a. a class_name -> a = function Foo -> (self : #foo_t :> foo_t) | _ -> ((raise Bad_cast) : a) method foo = "foo" end (* Now we can create a subclass of foo *) class type bar_t = object inherit foo method bar: string end extend 'a class_name with Bar: bar_t class_name class bar: bar_t = object(self) inherit foo as super method cast: type a. a class_name -> a = function Bar -> (self : #bar_t :> bar_t) | other -> super#cast other method bar = "bar" end (* Now lets create a mutable list of castable objects *) let clist :castable list ref = ref [] let push_castable (c: #castable) = clist := (c :> castable) :: !clist let pop_castable () = match !clist with c :: rest -> clist := rest; c | [] -> raise Not_found;; (* We can add foos and bars to this list, and retrive them *) push_castable (new foo);; push_castable (new bar);; push_castable (new foo);; let c1: castable = pop_castable () let c2: castable = pop_castable () let c3: castable = pop_castable () (* We can also downcast these values to foos and bars *) let f1: foo = c1#cast Foo let f2: foo = c2#cast Foo let f3: foo = c3#cast Foo let b2: bar = c2#cast Bar