Dear Clean team,

I'm trying a two-dimensional array update in-place... and got lost.

I have this utility function I did a while ago for update in place for 
one-dimensional arrays...

// updates first parameter (array) in place with values from a function that 
takes as parameters the value at 
// index p and p itself
updateInPlace :: *(a e) (e Int -> e) Int -> *(a e) | Array a e
updateInPlace arr1 f maxPos = updateLoop_ arr1 f 0 maxPos
where
    updateLoop_ :: *(a e) (e Int -> e) Int Int -> *(a e) | Array a e
    updateLoop_ arr1 f pos maxPos
    | pos == maxPos  = arr1
    # (v, arr1) = arr1![pos]
    = {(updateLoop_ arr1 f (pos+1) maxPos) & [pos] = f v pos}

If not the best implementation, at least worked for me.


I'm now trying to port the following element-wise matrix multiplication (for 
the sake of a simple example)

times :: {{#Int}} {{#Int}} -> {{#Int}}
times m1 m2 = {{m1.[i,j] * m2.[i,j] \\ j <- [0..MAX_INDEX]} \\ i <- 
[0..MAX_INDEX]}

into an efficient update in place in the first parameter... but this throws a 
compilation error

times :: *{{#Int}} {{#Int}} -> *{{#Int}}
times m1 m2 = updateInPlace m1 rowUpdate SIZE
where
    rowUpdate :: *{#Int} Int -> *{#Int}
    rowUpdate row i = updateInPlace row (\v j = v * m2.[i,j]) SIZE

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.

Am I missing something?

Kind regards
Carlos
p.s. attached test2.icl with extracted code above



      

Attachment: test2.icl
Description: Binary data

_______________________________________________
clean-list mailing list
[email protected]
http://mailman.science.ru.nl/mailman/listinfo/clean-list

Reply via email to