<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial,helvetica,sans-serif;font-size:10pt;color:#00007f;"><div>Dear Clean team,<br><br>I'm trying a two-dimensional array update in-place... and got lost.<br><br>I have this utility function I did a while ago for update in place for one-dimensional arrays...<br><br>// updates first parameter (array) in place with values from a function that takes as parameters the value at <br>// index p and p itself<br>updateInPlace :: *(a e) (e Int -> e) Int -> *(a e) | Array a e<br>updateInPlace arr1 f maxPos = updateLoop_ arr1 f 0 maxPos<br>where<br> updateLoop_ :: *(a e) (e Int -> e) Int Int -> *(a e) | Array a e<br> updateLoop_ arr1 f pos maxPos<br> | pos == maxPos = arr1<br> # (v, arr1) = arr1![pos]<br> = {(updateLoop_ arr1 f (pos+1) maxPos) & [pos]
= f v pos}<br><br>If not the best implementation, at least worked for me.<br><br><br>I'm now trying to port the following element-wise matrix multiplication (for the sake of a simple example)<br><br>times :: {{#Int}} {{#Int}} -> {{#Int}}<br>times m1 m2 = {{m1.[i,j] * m2.[i,j] \\ j <- [0..MAX_INDEX]} \\ i <- [0..MAX_INDEX]}<br><br>into an efficient update in place in the first parameter... but this throws a compilation error<br><br>times :: *{{#Int}} {{#Int}} -> *{{#Int}}<br>times m1 m2 = updateInPlace m1 rowUpdate SIZE<br>where<br> rowUpdate :: *{#Int} Int -> *{#Int}<br> rowUpdate row i = updateInPlace row (\v j = v * m2.[i,j]) SIZE<br><br>And the error refers to rowUpdate, I believe, but refers to it curried, [i.e. like A -> (B -> C) instead of A B -> C]... and says that (B -> C) must be unique, I'm lost.<br><br>Am I missing something?<br><br>Kind regards<br>Carlos<br>p.s. attached
test2.icl with extracted code above<br></div>
</div><br>
</body></html>