GHC has a lot of optimizations that it can perform, but I don’t know what they all are, nor how likely they are to be performed and under what circumstances.
My question is: what transformations can I expect it to apply every time, or nearly so? If I look at a piece of code that’s going to be executed (evaluated) frequently and my first thought is “hmm, maybe I should optimize that”, in which cases should my second thought be, “don’t even think about it, GHC got this”?
I was reading the paper Stream Fusion: From Lists to Streams to Nothing at All, and the technique they used of rewriting list processing into a different form which GHC’s normal optimizations would then reliably optimize down into simple loops was novel to me. How can I tell when my own programs are eligible for that kind of optimization?
There’s some information in the GHC manual, but it only goes part of the way towards answering the question.
EDIT: I’m starting a bounty. What I would like is a list of lower-level transformations like lambda/let/case-floating, type/constructor/function argument specialization, strictness analysis and unboxing, worker/wrapper, and whatever else significant GHC does that I’ve left out, along with explanations and examples of input and output code, and ideally illustrations of situations when the total effect is more than the sum of its parts. And ideally some mention of when transformations won’t happen. I’m not expecting novel-length explanations of every transformation, a couple of sentences and inline one-liner code examples could be enough (or a link, if it’s not to twenty pages of scientific paper), as long as the big picture is clear by the end of it. I want to be able to look at a piece of code and be able to make a good guess about whether it will compile down to a tight loop, or why not, or what I would have to change to make it. (I’m not interested so much here in the big optimization frameworks like stream fusion (I just read a paper about that); more in the kind of knowledge that people who write these frameworks have.)