Hi, Am Freitag, den 04.12.2009, 10:36 +0000 schrieb Neil Brown: > But let's say you have: > > g x y = f x y * f x y > > Now the compiler (i.e. at compile-time) can do some magic. It can > spot the common expression and know the result of f x y must be the > same both times, so it can convert to: > > g x y = let z = f x y in z * z > > Now, the Haskell run-time will evaluate f x y once, store the result > in z, and use it twice. That's how it can use commonalities in your > code and avoid multiple evaluations of the same function call, which I > *think* was your question.
Note that although the compiler _could_ do this transformation, it does not actually do it because of some unwanted subtleties: http://www.haskell.org/haskellwiki/GHC:FAQ#Does_GHC_do_common_subexpression_elimination.3F (I was a bit disappointed when I found out about this, after first hearing how much great optimization a haskell compiler _could_ do, but that’s reality.) Greetings, Joachim -- Joachim "nomeata" Breitner mail: [email protected] | ICQ# 74513189 | GPG-Key: 4743206C JID: [email protected] | http://www.joachim-breitner.de/ Debian Developer: [email protected]
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
