diff options
Diffstat (limited to 'library')
-rw-r--r-- | library/states.ml | 7 | ||||
-rw-r--r-- | library/states.mli | 5 |
2 files changed, 12 insertions, 0 deletions
diff --git a/library/states.ml b/library/states.ml index c985dcf2c..4fbc4c886 100644 --- a/library/states.ml +++ b/library/states.ml @@ -35,3 +35,10 @@ let with_heavy_rollback f x = f x with reraise -> (unfreeze st; raise reraise) + +let with_state_protection f x = + let st = freeze () in + try + let a = f x in unfreeze st; a + with reraise -> + (unfreeze st; raise reraise) diff --git a/library/states.mli b/library/states.mli index 3deb05658..17f62b512 100644 --- a/library/states.mli +++ b/library/states.mli @@ -26,4 +26,9 @@ val unfreeze : state -> unit val with_heavy_rollback : ('a -> 'b) -> 'a -> 'b +(*s [with_state_protection f x] applies [f] to [x] and restores the + state of the whole system as it was before the evaluation of f *) + +val with_state_protection : ('a -> 'b) -> 'a -> 'b + |