Re: Repeated computations under a lambda

2017-07-19 Thread Conal Elliott
> 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

RE: Repeated computations under a lambda

2017-07-19 Thread Simon Peyton Jones via ghc-devs
peated computations under a lambda 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. With

Re: Repeated computations under a lambda

2017-07-18 Thread Joachim Breitner
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

Re: Repeated computations under a lambda

2017-07-18 Thread 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

Re: Repeated computations under a lambda

2017-07-18 Thread David Feuer
On Tuesday, July 18, 2017 3:55:28 PM EDT Conal Elliott wrote: > Hi Sebastian, > > Thanks for the reply. It's that I don't want `exampleC` to be eta-expanded. > Apparently GHC does by default even when doing so moves computation under > lambda. I've thought otherwise for a very long time. GHC

Re: Repeated computations under a lambda

2017-07-18 Thread Conal Elliott
Hi Sebastian, Thanks for the reply. It's that I don't want `exampleC` to be eta-expanded. Apparently GHC does by default even when doing so moves computation under lambda. I've thought otherwise for a very long time. -- Conal On Tue, Jul 18, 2017 at 9:48 AM, Sebastian Graf

Re: Repeated computations under a lambda

2017-07-18 Thread Conal Elliott
> the exampleC is the bound things that is eta-expanded. Oh! I get it now. Thanks. > The problem is that GHC’s optimizer uses a cost-model [...] that does not hold in your case. Makes sense a well. I'll use `-fno-do-lambda-eta-expansion` for now and see well it works. Thanks very much for

Re: Repeated computations under a lambda

2017-07-18 Thread Joachim Breitner
Hi Conal, Am Dienstag, den 18.07.2017, 15:35 -0700 schrieb Conal Elliott: > Thanks very much for this reply, Joachim. I see that `-fno-do-lambda- > eta-expansion` with my example prevents moving the computation under > the lambda where it gets repeatedly evaluated. I don't understand > what this

Re: Repeated computations under a lambda

2017-07-18 Thread Conal Elliott
Thanks very much for this reply, Joachim. I see that `-fno-do-lambda-eta-expansion` with my example prevents moving the computation under the lambda where it gets repeatedly evaluated. I don't understand what this code motion/substitution has to do with eta-expansion. Is it that the `let`

Re: Repeated computations under a lambda

2017-07-18 Thread Joachim Breitner
Hi, Am Dienstag, den 18.07.2017, 08:34 -0700 schrieb Conal Elliott: > I'm seeing what looks like repeated computation under a lambda with > `-O` and `-O2`. The following definition: > > > exampleC :: Double -> Double -> Double > > exampleC = \ t -> let s = sin t in \ x -> x + s > > yields this

Re: Repeated computations under a lambda

2017-07-18 Thread Sebastian Graf
Hi Conal, so if I understand this right, you'd rather not wanted `exampleC` to be eta-expanded (or the binding of `s` to be floated into the lambda)? Or is it that you want CSE to find out that you always supply the same `t` as the first argument and share the partial application and thus the