How to write nested loop problem using parallel strategies in Haskell
I'm playing with parallel strategies and wondering if I'm doing the following the right way. Java code:

	    double x = 0.0;
	    double[] arr = new double[2000];
	    
	    for (int i = 0; i < arr.length; i++) 
	    	arr[i] = i;

	    for (int i = 0; i < arr.length; i++) {
	        x += arr[i] * 5;

	        for (int j = i + 1; j < arr.length; j++)
	        	x -= arr[j] * 3;
	    }
Haskell program which uses parallel strategies to compute the result:


		n = 2000
		ns = [0..n-1]

		segments = chunk 100 ns
				
		chunk n [] = []
		chunk n xs = ys : chunk n zs
		  where (ys,zs) = splitAt n xs

		parCompute = foldl' (+) 0 (map (\ts -> compute ts) segments `using` parList rdeepseq)
		  
		compute ts = foldl' addfunc 0 ts
			where
				addfunc acc i = (acc + x) - (foldl' minusfunc 0 [(i+1)..(n-1)])
					where
						x = (ns!!i) * 5
						minusfunc acc' j = (acc' + x')
							where
								x' = (ns!!j) * 3
								
		main = print parCompute

My questions are:

- is it right to use foldl' here? I thought since all computations need to be done to get the result, I should force evaluate.

- is there a better way to use segments? what common patterns are present in this problem that i can exploit?

- what other strategies could be applied to this problem? Also, any possibility of parallelising just using `par` and `seq` primitives.
How to write nested loop problem using parallel strategies in Haskell
===

I'm playing with parallel strategies and wondering if I'm doing the following the right way. Java code:

	    double x = 0.0;
	    double[] arr = new double[2000];
	    
	    for (int i = 0; i < arr.length; i++) 
	    	arr[i] = i;

	    for (int i = 0; i < arr.length; i++) {
	        x += arr[i] * 5;

	        for (int j = i + 1; j < arr.length; j++)
	        	x -= arr[j] * 3;
	    }
Haskell program which uses parallel strategies to compute the result:


		n = 2000
		ns = [0..n-1]

		segments = chunk 100 ns
				
		chunk n [] = []
		chunk n xs = ys : chunk n zs
		  where (ys,zs) = splitAt n xs

		parCompute = foldl' (+) 0 (map (\ts -> compute ts) segments `using` parList rdeepseq)
		  
		compute ts = foldl' addfunc 0 ts
			where
				addfunc acc i = (acc + x) - (foldl' minusfunc 0 [(i+1)..(n-1)])
					where
						x = (ns!!i) * 5
						minusfunc acc' j = (acc' + x')
							where
								x' = (ns!!j) * 3
								
		main = print parCompute

My questions are:

- is it right to use foldl' here? I thought since all computations need to be done to get the result, I should force evaluate.

- is there a better way to use segments? what common patterns are present in this problem that i can exploit?

- what other strategies could be applied to this problem? Also, any possibility of parallelising just using `par` and `seq` primitives.