Suppose 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. mapdefined like this:
map f l = f (head l) : (map f (tail l))
So, we get:
f (head (map g [1..100]))
And then applied again:
f (g (head [1..100]))
The result is
f (g 1)
No interim lists are created, simply because of laziness.
Is this analysis correct? And with simple structures like this:
foldl' ... $ map f1 $ map f2 $ createlist
are intermediate lists that have ever been created, even without "merging lists"? (I think laziness should eliminate them trivially).
The only place I can find a reason to save the list is if:
l' = [1..100]
l = map f (map g l')
l', . l' , , .