I can only answer the questions to the best of my understanding, here goes:
On 9 October 2015 at 17:00, Rob Stewart
<robstewart57@gmail.com> wrote:
Here are my questions: what exactly is the call overhead of a
non-inlned Haskell function? What additional runtime work needs to
happen when calling to a non-inlined function? Specifically what other
GHC optimisations are possible only if function inlining happens
first? Can anyone provide a simple example where 1) a function is not
inlined, versus 2) when that function is inlined, which demonstrates
two things: 1) a GHC report of the additional optimisations that were
applied because of inlining and 2) shorter program runtime as a result
of inlining.
An example of optimizations becoming available after inlining:
listAdd1 = map (+1)
listAdd2 = map (+2)
listAdd3 = listAdd2 . listAdd1
-- From the RHS of listAdd3
listAdd2 . listAdd1
== map (+2) . map (+1)
== map ((+2) . (+1)) -- List fusion. Also works for types other than lists (see the talk [1] for more)
== map (\x -> (+2) ((+1) x)) -- Inline the composition dot-operator (.)
== map (\x -> (+2) (x + 1))
== map (\x -> x + 3)
== map (+3)
-- The order and the final result might not be the same, but it will be operationally equivalent.
-- This prevents having to iterate over the whole list twice.