for (int i = 0; i < N; i++) {
a[i] = 2*b[i];
}
for (int i = 0; i < N; i++) {
c[i] = 2*d[i];
}
into for (int i = 0; i < N; i+=2) {
a[i] = 2*b[i];
a[i+1] = 2*b[i+1];
c[i] = 2*d[i];
c[i+1] = 2*d[i+1];
}
It seems like GHC ought to similarly be able to turn some foo :: [Int] -> [Int]
into foo :: [(Int, Int)] -> [(Int, Int)]
under the covers for a similar speedup as long as it can, as with the C compiler, handle the case of an odd length with a bit of extra code.There are limits to how much you can restructure a list that's exported outside the compilation unit (my Haskell knowledge is fuzzy here so that's probably not the right terminology). And if the list is being re-stitched in odd ways it might be a bad idea. But as far as I can tell it ought to be doable and useful in most common cases. Of course maybe it's already doing this in those cases where it can prove that it works and that's why Haskell performance generally is good but fragile.