(* do-it-yourself objects using references *) type obj = {get : unit -> int; inc : unit -> unit; reset : unit -> unit} (* val make : unit -> obj *) let make() = let r = ref 0 in {get = (function () -> !r); inc = (function () -> r := !r + 1); reset = (function () -> r := 0)} (* try let x = make();; x.get();; x.inc();; x.inc();; x.get();; x.reset();; x.get();; *)