Haskell: List fusion, where is it needed?
Lets say we have the following:

    l = map f (map g [1..100])

And we want to do:

    head l

So we get:

    head (map f (map g [1..100]))

Now, we have to get the first element of this. `map` is defined something like so:

    map f l = f (head l) : (map f (tail l))

So then we get:

    f (head (map g [1..100]))

And then applied again:

    f (g (head [1..100]))

Which results in

    f (g 1)

No intermediate lists are formed, simply due to laziness.

Is this analysis correct? And with simple structures like this:

    foldl' ... $ map f1 $ map f2 $ createlist

are intermediate lists ever created, even without "list fusion"? (I think laziness should eliminate them trivially).

Haskell: List fusion, where is it needed?
===

Lets say we have the following:

    l = map f (map g [1..100])

And we want to do:

    head l

So we get:

    head (map f (map g [1..100]))

Now, we have to get the first element of this. `map` is defined something like so:

    map f l = f (head l) : (map f (tail l))

So then we get:

    f (head (map g [1..100]))

And then applied again:

    f (g (head [1..100]))

Which results in

    f (g 1)

No intermediate lists are formed, simply due to laziness.

Is this analysis correct? And with simple structures like this:

    foldl' ... $ map f1 $ map f2 $ createlist

are intermediate lists ever created, even without "list fusion"? (I think laziness should eliminate them trivially).
