Can anyone provide an example showing the addition of two arrays in Haskell please?
I'm fairly new to Haskell, and I generally find that I can learn quicker by taking something simple that I understand in one language and seeing how another programmer might do it in their language.
It would be great to see some code that creates two arrays of floats and calls a function which results in an array with the summed values. Something equivalent to the following C code.
void addTwoArrays(float *a, float *b, float *c, int len) {
int idx=0;
while (idx < len) {
c[idx] = a[idx] + b[idx];
}
}
int N = 4;
float *a = (float*)malloc(N * sizeof(float));
float *b = (float*)malloc(N * sizeof(float));
float *c = (float*)malloc(N * sizeof(float));
a[0]=0.0; a[1]=0.1; a[2]=0.2; a[3]=0.4;
b[0]=0.0; b[1]=0.1; b[2]=0.2; b[3]=0.4;
addTwoArrays(a,b,c,N);
Seeing Haskell code that achieved the same result would help my understanding a lot. I guess the haskell version would create the result array and return it, like c = addTwoArrays(a,b,N)?
Thanks.