<div dir="ltr"><div>> GHC does this transformation not nilly-willy, .... If that</div><div>> code would call some unknown function, or allocate memory, then GHC</div><div>> would certainly preserve your intention.</div><div><br></div><div>Wonderful. Thanks for the clarification.</div><div><br></div><div>-- Conal</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 18, 2017 at 6:51 PM, Joachim Breitner <span dir="ltr"><<a href="mailto:mail@joachim-breitner.de" target="_blank">mail@joachim-breitner.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<span class=""><br>
Am Dienstag, den 18.07.2017, 17:01 -0700 schrieb Conal Elliott:<br>
> Here's the code in question, slightly rephrased:<br>
><br>
> > exampleC t = \ x -> x + s where s = sin t<br>
><br>
> I wrote it this way so that `sin t` would be computed once per `t`<br>
> and reused for each value of `x`. The intermediate result `s` has<br>
> type `Double`---not a function. Without `-fno-do-lambda-eta-<br>
> expansion`, phase 2 of `ghc -O` causes the `s = sin t` binding to be<br>
> moved under the `\ x -> ...`. I've been using this programming style<br>
> for this purpose for longer than I can remember, and apparently I've<br>
> been mistaken about its effectiveness at least part of that time.<br>
<br>
</span>usually it is very effective. GHC does this transformation not nilly-<br>
willy, but only when its heuristics indicate that it is ok, usually<br>
because the operation (here sin) is known to be very cheap. If that<br>
code would call some unknown function, or allocate memory, then GHC<br>
would certainly preserve your intention.<br>
<br>
Greetings,<br>
Joachim<br>______________________________<wbr>_________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/ghc-devs</a><br>
<br></blockquote></div><br></div>