Une MAJ de sécurité est nécessaire sur notre version actuelle. Elle sera effectuée lundi 02/08 entre 12h30 et 13h. L'interruption de service devrait durer quelques minutes (probablement moins de 5 minutes).

Commit 0065ba02 authored by Jean-Christophe Filliâtre's avatar Jean-Christophe Filliâtre
Browse files

new function memoize_rec

parent 919a49b2
......@@ -89,6 +89,9 @@ module type S = sig
val memoize : int -> (key -> 'a) -> (key -> 'a)
(* create a memoizing function *)
val memoize_rec : int -> ((key -> 'a) -> (key -> 'a)) -> (key -> 'a)
(* create a memoizing recursive function *)
val memoize_option : int -> (key option -> 'a) -> (key option -> 'a)
(* memoizing functions on option types *)
......@@ -218,6 +221,17 @@ module Make (S : Weakey) = struct
set h e v;
v
let memoize_rec n fn =
let h = create n in
let rec f e =
try find h e
with Not_found ->
let v = fn f e in
set h e v;
v
in
f
let memoize_option n fn =
let v = lazy (fn None) in
let fn e = fn (Some e) in
......
......@@ -68,6 +68,9 @@ module type S = sig
val memoize : int -> (key -> 'a) -> (key -> 'a)
(* create a memoizing function *)
val memoize_rec : int -> ((key -> 'a) -> (key -> 'a)) -> (key -> 'a)
(* create a memoizing recursive function *)
val memoize_option : int -> (key option -> 'a) -> (key option -> 'a)
(* memoizing functions on option types *)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment