*{:*{:Real:}:}

johnvg@cs.kun.nl johnvg@cs.kun.nl
Thu, 28 Mar 96 13:29:18 +0100


Jan Krynicky wrote:

> How I construct a value of this type?
>
> Simply I can construct an unique array, but not an array with unique 
> items if I don't know it's size.
>
> a::*{:*{:Real:}:}
> a = {:a1,a2,a3:}
>  where
>   a1 = {: 1.0,2.0 :}
>   a2 = {: 3.5,4.7 :}
>   a3 = {: 5.1,6.0 :}
>
> is fine, but I need something like
>
> a = zeros 2 3
>
> -> a :: *{:*{:Real:}:} = {: {:0.0, 0.0, 0.0:}, {:0.0, 0.0, 0.0:} :}
>
> I'd like mkArray to be of type
> :: !Int (Int -> .a) -> *{: .a :}
> instead of
> :: !Int (Int -> a)  -> *{:a:}

In Clean 1.0 (and also in 1.1) it is not possible to construct arrays with
unique elements. This will be changed in later versions of the compiler.

The reason for this is that unique elements cannot be retrieved from an array.
After the 'uselect' the element is still in the array, so there are
2 references to the array element, and thus it is no longer unique.

To be able to use such arrays we will likely:

- change the compiler so that it will recognize more-dimensional selections
  and updates, and prevent loss of of uniqueness information in these
  cases. You could then use:

    increment a=:{[i,j]=aij} i j
       = {a & [i,j] = aij+1}

  to increment an element in 2-dimensional integer array with unique rows.
  (note: in Clean 1.0 you would write {: and :} instead of { and })

- implement observation types. 'increment' can then also be defined with:

    increment a i j = let! aij = a.[i,j]
                      in {a & [i,j] = aij+1}

- add a function which selects an element from an array, and replaces this
  element (in the array) by another value.  Using this function the
  'increment' function could be written as:

    increment a0 i j = {a1 & [i] = increment_row_element ai j}
	where
        (ai,a1) = replace a0 i (createArray 0 0)

		increment_row_element ai=:{[j]=aij} j = {ai & [j] = aij+1}
		
  This 'replace' function has already been implemented, but is not yet
  available in Clean 1.1.

--
John van Groningen
johnvg@cs.kun.nl