[clean-list] stuck with uniqueness in records

Carlos Aya carlosayam at yahoo.com.au
Fri Nov 27 10:35:39 MET 2009


Dear All,

Continuing with array update, now I want to wrap the array into a record. Basically to convert it into a 2D matrix. I want to put it into an abstract type, like

---- UMatrix.dcl ------
definition module UMatrix

import StdArray, StdClass

// UMatrix : Unboxed matrix, elemType must be one of the available unboxed types
::UMatrix elemType | Array {#} elemType

// ... more stuff ...

---------------------------

with the following implementation module:

---- UMatrix.icl ------
implementation module UMatrix

import StdArray, StdInt, StdBool, StdMisc, StdList, StdEnum

::UMatrix elemType = { rows :: !Int
                     , cols :: !Int
                     , vals :: ({#} elemType)
                     }
                

//  ... more stuff ...

---------------------------

The problem I am facing is update in place of the array vals, I want to have the following function (from implementation)

...........................
// adds one matrix onto another (in place add)
fAdd :: *(UMatrix elemType) (UMatrix elemType) -> *(UMatrix elemType) | Array {#} elemType & Arith elemType
fAdd m1 m2
| sameSize m1 m2
    # (arr, m1) = m1!vals   // <--- PROBLEM HERE
    = {m1 & vals = updateInPlace arr f (size m2.vals)}
= abort "Invalid matrix add"
where
    f v p = v + m2.vals.[p]

// ...
// .. where updateInPlace is the array update in-place which I put together with your help before. ...
// ...

// updates array first parameter with a function taking its value at 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}                 
............................


The problem is that updateInPlace expects a unique array, but the signature I am getting in PROBLEM HERE is

m1!vals :: ({#a}, u:(UMatrix v:a))

i.e., the array inside the record is not unique (at least, this is how I understand it).

I have tried to define UMatrix with . and attribute variables in the hope that it will change the signature of the record "!" operator, but with no luck. And read the manual and the clean book but nothing said in b&w about the "!" operator, at least for me as I couldn't link the whole concept of uniqueness propagation for records.

How can I extract the array from the unique parameter in fAdd and expect it to be unique?

Thanks in advance

Carlos


      __________________________________________________________________________________
Last chance to win a Sony entertainment pack thanks to Yahoo!7. Hurry, ends Nov 30. Enter now: http://au.docs.yahoo.com/homepageset/



More information about the clean-list mailing list