Created
June 19, 2015 11:38
-
-
Save gsg/03d886ae7d05c0391bcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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