How can I get at the cleverest optimizations that GHC makes?

Because I can see it coming: this is a different question than What optimizations can GHC be expected to perform reliably? because I'm not asking for the most reliable optimizations, just the most clever/powerful.

I'm specifically looking for non-intuitive optimizations that GHC makes that can have serious impacts on performance and demonstrate the power of compiler optimizations related to lazy evaluation or purity. And direct explanations about how to get at them.

The best answers will have:

  • An explanation of the optimization and why it is so clever or powerful
  • Why the optimization improves performance
  • How GHC recognizes when it can use this optimization
  • What the optimization actually transforms the code into
  • Why this optimization requires lazy evaluation or purity

  • Stream fusion is probably the biggest one. It turns something like sum . map (+1) . filter (>5) sum . map (+1) . filter (>5) sum . map (+1) . filter (>5) , which nominally allocates two new lists, into a simple loop that operates in constant space.

    链接地址: http://www.djcxy.com/p/7474.html

    上一篇: GHC优化

    下一篇: 我怎样才能得到GHC最聪明的优化?