[Haskell-cafe] does the compiler optimize repeated calls?

Tamas K Papp tpapp at Princeton.EDU
Wed Sep 6 08:27:03 EDT 2006


Hi,

I have a question about coding and compilers.  Suppose that a function
is invoked with the same parameters inside another function declaration, eg

-- this example does nothing particularly meaningless
g a b c = let something1 = f a b
      	      something2 = externalsomething (f a b) 42
	      something3 = externalsomething2 (137 * (f a b)) in
	      ...

Does it help (performancewise) to have

g a b c = let resultoff = f a b
      	      something2 = externalsomething resultoff 42
	      something3 = externalsomething2 (137 * resultoff) in
	      ...

or does the compiler perform this optimization?  More generally, if a
function is invoked with the same parameters again (and it doesn't
involve anything like monads), does does it makes sense
(performancewise) to "store" the result somewhere?

Thank you,

Tamas

PS: I realize that I am asking a lot of newbie questions, and I would
like to thank everybody for their patience and elucidating replies.


More information about the Haskell-Cafe mailing list