type pt = {
get_x : unit -> int;
set_x : int -> unit;
distance : pt -> int;
}
let point1_constructor () = (* unit -> pt *)
let x = ref 0 in
let rec self =
{ get_x = (fun () -> !x);
set_x = (fun y -> x := y);
distance = (fun p -> p.get_x() - self.get_x() )
}
in self
(* this won't type-check, but even if it did, it would not
do dynamic dispatch, the essence of OOP *)
(*
let point2_constructor () =
let r = point1_constructor () in
let y = ref 0 in
let rec self =
{ get_x = (fun () -> 34 + r.get_x());
set_x = r.set_x;
distance = r.distance;
get_y = (fun () -> !y) }
in self
*)