caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: lpw25@cam.ac.uk
To: caml-list@inria.fr
Subject: [Caml-list] Open datatypes
Date: Thu, 14 Jul 2011 15:38:18 +0200	[thread overview]
Message-ID: <sympa.1310649571.28612.849@inria.fr> (raw)
In-Reply-To: 


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

             reply	other threads:[~2011-07-14 13:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-14 13:38 lpw25 [this message]
2011-07-14 14:48 ` Markus Mottl
2011-07-14 15:10   ` Gerd Stolpmann
2011-07-14 16:05     ` Leo P White
2011-07-14 15:15   ` 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=sympa.1310649571.28612.849@inria.fr \
    --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;
as well as URLs for NNTP newsgroup(s).