From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p6EDcOTE028642 for ; Thu, 14 Jul 2011 15:38:24 +0200 X-IronPort-AV: E=Sophos;i="4.65,529,1304287200"; d="scan'208";a="98533797" Received: from walapai.inria.fr ([128.93.30.24]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 14 Jul 2011 15:38:19 +0200 Received: from walapai.inria.fr (localhost [127.0.0.1]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p6EDcISR028639 for ; Thu, 14 Jul 2011 15:38:18 +0200 Received: (from sympa@localhost) by walapai.inria.fr (8.13.6/8.12.10/Submit) id p6EDcIwP028638 for caml-list@inria.fr; Thu, 14 Jul 2011 15:38:18 +0200 Date: Thu, 14 Jul 2011 15:38:18 +0200 X-Authentication-Warning: walapai.inria.fr: sympa set sender to sympa@inria.fr using -f To: caml-list@inria.fr From: lpw25@cam.ac.uk In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: [Caml-list] Open datatypes Hi all, I was wondering whether there was any particular reason why OCaml doesn't allow the user to create open extensible datatypes like exn. I know that something similar can be created using local exceptions: module T = struct type t = exn type 'a tvariant = (('a -> t), (t -> 'a option)) let createVariant (type s) () = let module M = struct exception E of s end in (fun x -> M.E x), (function M.E x -> Some x | _ -> None) let mkTVariant ((cnstr, _) : 'a tvariant) (x: 'a) = cnstr x let matchTVariant ((_, destr) : 'a tvariant) (xt: t) = destr xt end but it isn't very neat, and it seems that it would not be that difficult to allow the user to declare types with the same properties as exn. Thanks, Leo