Source

ocaml-pure-polyrecord / polyrecord.ml

Full commit
type 'a t = (int, Obj.t) Hashtbl.t

let create ko = 
  let tbl = Hashtbl.create 31 in
  List.iter (fun (k,o) -> Hashtbl.add tbl k o) ko;
  tbl

let update t ko = 
  let t = Hashtbl.copy t in
  List.iter (fun (k,o) -> Hashtbl.replace t k o) ko;
  t

let get t k = Hashtbl.find t k

let set t k o = (Obj.magic (Hashtbl.find t k) : Obj.t ref) := o