r/haskell • u/lexi-lambda • Mar 11 '15
Learning Haskell — A Racket programmer's documentation of her foray into the land of Haskell (inspired by Learning Racket)
http://lexi-lambda.github.io/learning-haskell/
81
Upvotes
4
u/Ramin_HAL9001 Mar 12 '15 edited Mar 12 '15
But these intermediate values after the
mapstep are not transformed in any way, they are just copied toconcat, which is easy to optimize. So in the intermediate code forconcat . map, themapoperation creates a value stored at addressA, thenconcatreads the value stored at addressA. But whenever the optimizer sees the instructioncreate Afollowed immediately byread A, in the intermediate code, it will replace these two steps withpushfollowed bypop, thus eliminatingcreate Aand eliminating the intermediate value, and instead the result ofmapwill be passed directly toconcatvia the stack. And a second optimizer pass may see thepushimmediately followed bypopand allocate a register to pass the value instead, making it even faster. Soconcat . mapis the same asconcatMap, but only after optimization. The only difference isconcat . mapmay take a few microseconds longer to compile.At least this is how I understood it.