Skip to content

Instantly share code, notes, and snippets.

@gsg
Created June 19, 2015 11:38
Show Gist options
  • Save gsg/03d886ae7d05c0391bcf to your computer and use it in GitHub Desktop.
Save gsg/03d886ae7d05c0391bcf to your computer and use it in GitHub Desktop.
module RRef : RREF = struct
type snap = SNil : snap | SCons : 'a * 'a ref * snap -> snap
type reflist = RNil : reflist | RCons : 'a ref * reflist -> reflist
let cell_list = ref RNil
let rref x =
let r = ref x in
cell_list := RCons (r, !cell_list);
r
let snapshot () =
let rec loop = function
| RNil -> SNil
| RCons (r, rest) -> SCons (!r, r, loop rest) in
loop !cell_list
let rec reload = function
| SNil -> ()
| SCons (x, r, rest) -> r := x; reload rest
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment