1. Dmitry Grebeniuk
  2. ocaml-dynatvar


ocaml-dynatvar / dynvar.mli

(** Dynamically typed variables

WARNING!  It's not tested yet!

Author: Dmitry Grebeniuk - gdsfh1 \@ gmail dot com

(** 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