diff options
author | Hugo Herbelin <Hugo.Herbelin@inria.fr> | 2017-08-21 23:49:20 +0200 |
---|---|---|
committer | Hugo Herbelin <Hugo.Herbelin@inria.fr> | 2017-09-12 20:17:27 +0200 |
commit | 8b07b9296dac108d7a3d44db227bb1c6042db555 (patch) | |
tree | 63a788b3e9fc6c4094b86417058f06f630b3bc01 /lib/util.ml | |
parent | cc94172036789cfef28007f59510b7f17df5d45d (diff) |
Adding function to be typically used to pass values from an OCaml "when" clause.
Diffstat (limited to 'lib/util.ml')
-rw-r--r-- | lib/util.ml | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/util.ml b/lib/util.ml index 36282b2da..6de012da0 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -171,3 +171,12 @@ let open_utf8_file_in fname = let s = Bytes.make 3 ' ' in if input in_chan s 0 3 < 3 || not (is_bom s) then seek_in in_chan 0; in_chan + +(** A trick which can typically be used to store on the fly the + computation of values in the "when" clause of a "match" then + retrieve the evaluated result in the r.h.s of the clause *) + +let set_temporary_memory () = + let a = ref None in + (fun x -> assert (!a = None); a := Some x; x), + (fun () -> match !a with Some x -> x | None -> assert false) |