Browse thread
forbidden construct as right hand side of "let rec"
-
Mathias Kende
-
Stéphane Glondu
- Lukasz Stafiniak
-
Mathias Kende
- Stéphane Glondu
- Xavier Leroy
-
Stéphane Glondu
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2009-10-25 (15:04) |
From: | Stéphane Glondu <steph@g...> |
Subject: | Re: [Caml-list] forbidden construct as right hand side of "let rec" |
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