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

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to