Why isn't ($) inlining when I want?

David Feuer david.feuer at gmail.com
Sat Aug 30 01:44:03 UTC 2014


On Thu, Aug 28, 2014 at 6:22 AM, Simon Peyton Jones
<simonpj at microsoft.com> wrote:
> Oh, now I understand.  In
>
>     loop g = sum . map g $ [1..1000000]
>
> GHC can share [1..100000] across all calls to loop, although that nixes
> fusion.  Because each call of loop may have a different g.
>
> But in
>
>     loop' = sum . map (+1) $ [1..1000000]
>
> GHC can share (sum . map (+1) $ [1..1000]) across all calls to loop’, so it
> can readily fuse the sum, map, and [1..n].
>
> I hope that explains it.
>
> Simon

To my mind, that's a great argument against full laziness. If I wanted
to share [1..100000] across all calls to loop, I would surely write
either

giantList = [1..100000]
loop g = sum . map g $ giantList

or

loop = \g -> sum . map g $ giantList
  where
    giantList = [1..100000]

If we bump that list up to a few hundred megabytes, the floated
version probably just destroyed our cache performance. If we bump it
to a few gigabytes—oops, we just ran out of memory.

David


More information about the ghc-devs mailing list