From: "Stéphane Glondu" <steph@glondu.net>
To: Mathias Kende <mathias@kende.fr>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] forbidden construct as right hand side of "let rec"
Date: Sun, 25 Oct 2009 16:03:59 +0100 [thread overview]
Message-ID: <4AE468DF.806@glondu.net> (raw)
In-Reply-To: <f23ca73b320d0c61a4a72cd310658e59@quare.fr>
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
next prev parent reply other threads:[~2009-10-25 15:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-22 22:22 Mathias Kende
2009-10-22 22:34 ` [Caml-list] " Stéphane Glondu
2009-10-22 23:10 ` Lukasz Stafiniak
2009-10-23 15:35 ` Damien Guichard
2009-10-23 16:14 ` Marc de Falco
2009-10-23 17:51 ` blue storm
2009-10-25 14:11 ` Mathias Kende
2009-10-25 15:03 ` Stéphane Glondu [this message]
2009-10-28 16:52 ` Xavier Leroy
2009-10-28 22:44 ` Lukasz Stafiniak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4AE468DF.806@glondu.net \
--to=steph@glondu.net \
--cc=caml-list@yquem.inria.fr \
--cc=mathias@kende.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox