]>
Mathias Kende a écrit :
> [...] I also want to write :
> let rec h = t (f h)
> (with t : ('a -> 'b) -> 'a -> 'b) but here, I can't afford to use
> let rec h x = t (f h) x
> because t as some side effects and I need it to be evaluated only once.
Then what about:
let h =
let tmp = ref (fun x -> assert false) in
let res x = !tmp x in
tmp :=
(fun x ->
let y = t (f res) in
tmp := y;
y x);
res
Intuitively, the "tmp" reference caches the call to "t (f h)", but this
is otherwise the same technique as I gave earlier.
Cheers,
--
Stéphane