> GHC does this transformation not nilly-willy, .... If that > code would call some unknown function, or allocate memory, then GHC > would certainly preserve your intention.
Wonderful. Thanks for the clarification. -- Conal On Tue, Jul 18, 2017 at 6:51 PM, Joachim Breitner <[email protected]> wrote: > Hi, > > Am Dienstag, den 18.07.2017, 17:01 -0700 schrieb Conal Elliott: > > Here's the code in question, slightly rephrased: > > > > > exampleC t = \ x -> x + s where s = sin t > > > > I wrote it this way so that `sin t` would be computed once per `t` > > and reused for each value of `x`. The intermediate result `s` has > > type `Double`---not a function. Without `-fno-do-lambda-eta- > > expansion`, phase 2 of `ghc -O` causes the `s = sin t` binding to be > > moved under the `\ x -> ...`. I've been using this programming style > > for this purpose for longer than I can remember, and apparently I've > > been mistaken about its effectiveness at least part of that time. > > usually it is very effective. GHC does this transformation not nilly- > willy, but only when its heuristics indicate that it is ok, usually > because the operation (here sin) is known to be very cheap. If that > code would call some unknown function, or allocate memory, then GHC > would certainly preserve your intention. > > Greetings, > Joachim > _______________________________________________ > ghc-devs mailing list > [email protected] > http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs > >
_______________________________________________ ghc-devs mailing list [email protected] http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
