Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 752
reem Avatar asked Dec 30 '13 20:12

reem


1 Answers

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

like image 186
Dirk Holsopple Avatar answered Oct 29 '22 11:10

Dirk Holsopple