There are several tricky aspects of compiling a functional language:
what optimisations to perform, how to do them efficiently, and when,
or more precisely in what order, the optimisations should be done. The
literature discussing the first question is abundant, for the second
is somewhat sparse and for the third is almost non-existent.
This paper investigates -- using the Glasgow Haskell Compiler (GHC) --
when the optimisations should be performed to gain maximum benefits,
where maximum benefits is defined as shortest runtime, for a given set
of optimisations. We focus on GHC, because it has been developed as a
testbed for compiler research, but we stress that the techniques are
applicable to any other compiler for a functional language.