Source

ocaml-dynatvar / dynvar.mli

Full commit
(** Dynamically typed variables

WARNING!  It's not tested yet! *)

(** Exception [Type_error (value_type, used_with_type)] is
    raised by [get] if you are trying to get the value of
    wrong type.
*)
exception Type_error of (string * string)
;

(** Type of the value that represents the type of dynamic variable *)
type ty 'a;

(** Type of dynamic variable *)
type var;

(** [mktype typename] creates a value that represents the type of
    dynamic variables you can create.  (i.e. it's the witness
    of dynamic variable's type)
 *)
value mktype : string -> ty 'a
;

(** [var ty val] creates dynamic variable with type [ty]
    and value [val].  The success of this operation is guaranteed
    by OCaml's type system.
*)
value var : ty 'a -> 'a -> var
;

(** [get ty var] gets the value of dynamic variable [var]
    which should be created by [var ty val] with the same [ty].
    (same == "physically equal").
    @raise Type_error when types differ.
*)
value get : ty 'a -> var -> 'a
;