aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorGravatar Maxime Dénès <mail@maximedenes.fr>2017-10-03 12:14:23 +0200
committerGravatar Maxime Dénès <mail@maximedenes.fr>2017-10-03 12:14:23 +0200
commit723b1cbb1a3b0933abf5a78a2fbcdd7bdfc5cc23 (patch)
tree83a36c2063b2c53da24d01bf37f4144e06232260 /lib
parent9bcfb39b38fc6ed2973ecf0d510805f731442203 (diff)
parent8b07b9296dac108d7a3d44db227bb1c6042db555 (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')
-rw-r--r--lib/util.ml9
-rw-r--r--lib/util.mli5
2 files changed, 14 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)
diff --git a/lib/util.mli b/lib/util.mli
index d910e7e28..c54f5825c 100644
--- a/lib/util.mli
+++ b/lib/util.mli
@@ -137,3 +137,8 @@ val sym : ('a, 'b) eq -> ('b, 'a) eq
val open_utf8_file_in : string -> in_channel
(** Open an utf-8 encoded file and skip the byte-order mark if any. *)
+
+val set_temporary_memory : unit -> ('a -> 'a) * (unit -> 'a)
+(** 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 *)