1234567891011121314151617181920212223242526272829303132333435363738394041(* This file is part of BOGUE, by San Vu Ngoc *)(* A Tvar, or transform variable of type ('a,'b) is a variable of type 'b
attached to a variable of type 'a Var.t by a bi-directional transformation *)(* there is no caching *)moduleVar=B_vartype('a,'b)t={var:'aVar.t;t_from:'a->'b;t_to:'b->'a}(* Setting/getting the a value should be done directly via the variable [var] *)(* Get the b value from the var *)letgetv=Var.getv.var|>v.t_from(* Update the local var by giving the b value. Consider sendind the var_changed
event. Note that the composition "get o set" may not be the identity
function! *)letsetvvalue=Var.setv.var(v.t_tovalue)(* [var] is an Avar of type 'a *)letcreatevar~t_from~t_to={var;t_from;t_to}(* A simple tvar which simply executes an action when the local value 'b is
changed, and 'a has the same type as 'b *)letlocal_actionactionvalue=letvar=Var.createvalueinlett_fromx=xinlett_tox=action();xincreatevar~t_to~t_from