diff options
| author | Maxime Dénès | 2017-10-03 12:14:23 +0200 |
|---|---|---|
| committer | Maxime Dénès | 2017-10-03 12:14:23 +0200 |
| commit | 723b1cbb1a3b0933abf5a78a2fbcdd7bdfc5cc23 (patch) | |
| tree | 83a36c2063b2c53da24d01bf37f4144e06232260 /lib/util.ml | |
| parent | 9bcfb39b38fc6ed2973ecf0d510805f731442203 (diff) | |
| parent | 8b07b9296dac108d7a3d44db227bb1c6042db555 (diff) | |
Merge PR #1015: Adding a function to be typically used to pass values from an OCaml "when" clause to the r.h.s of the matching 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 36282b2dac..6de012da0e 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) |
