Fwd: [Haskell-beginners] Optimization Problem

Daniel Fischer daniel.is.fischer at web.de
Mon Aug 9 22:02:32 EDT 2010


On Tuesday 10 August 2010 03:06:46, MAN wrote:
> I believe the improvement was in avoiding the call to 'sqrt', rather
> than substituting (^2) by a mult.

That's the big one. sqrt is pretty expensive compared to a multiplication.

> Although that last substitution is always welcomed in C, GHC could
> easily make it for you.

It could, but it doesn't (at least not in core). Most of the time it 
doesn't make a significant difference whether you use (x ^ 2) or (x * x), 
but sometimes it can make a big difference (we had an example earlier this 
year, but I can't seem to find it now).


More information about the Beginners mailing list