Haskell performs a very cool optimization called "stream fusion" to deal with a whole class of traversal optimization problems; stream fusion removes intermediate list results completely, and bundles a bunch of things that look like maps/reduces/filters into a single operation. Your example doesn't quite hit it, but a similar bit of code like:
for (int i = 0; i < N; i++)
a[i] = 2 * b[i];
for (int i = 0; i < N; i++)
c[i] = 2 * a[i] + b[i];
t = 0;
for (int i = 0; i < N; i++)
if (b[i] % 2 == 0) t += c[i];
Would be rewritten to the equivalent of: t = 0;
for (int i = 0; i < N; i++)
if (b[i] % 2 == 0) t += 5 * b[i];
Lots more info on the GHC optimizations page: https://wiki.haskell.org/GHC_optimisations#Fusion