ocamlc -o test.exe polyrecord.cma test.out.ml

+type 'a t (** since it is mutable record, it must be invariant *)

val create : (int * Obj.t) list -> 'a t

val update : 'a t -> (int * Obj.t) list -> 'a t

-let ~~f~~ = {< x = 1; y = None >}

+let r = {< x = 1; y = None >}

-let g = {< f with x = 3 >}

-(* impos let g = {< f with z = 3 >} *)

-let _ = g..y <- Some 3 (* all the fields are mutable *)

(* those records are just hashtbls, so streamable *)

-let ~~_~~ = output_value stdout ~~f~~

+let () = output_value stdout r; print_newline ()

+let r2 = {< r with x = 3 >} (* make a copy *)

+(* impos let r2 = {< r with z = 3 >} *)

+let () = r2..y <- Some 3;; (* all the fields are mutable *)

+(* impos: since it is a ref

+ let () = r2..y <- Some 3.0;; (* all the fields are mutable *)

+let () = Printf.printf "%d\n" (match r2..y with None -> -1 | Some v -> v)