2 ms·
If f(a[i]) depends on f(a[i-1]) then you must necessarily recurse, I think the author already covered this case. It's basically a classic usage of fold: f
by yummyfajitas 15y ago
If f(a[i]) depends on f(a[i-1]) then you must necessarily recurse,
I think the author already covered this case. It's basically a classic usage of fold:
fold f a 0 = f(a[i], f(a[i-1], f(..., f(a[0], 0)...)))
He even points out that it's better for the compiler if code is written this way. I.e.:
a = map g inputData
b = fold f a 0
The compiler now knows the first line can be parallelized, whereas the second cannot. If the map were mixed up with the fold code (which it often is in big for loops), the compiler would have a harder time of it.