2Q: Stdio rationale & "systolic" array?

Pascal Serrarens pascalrs@cs.kun.nl
Fri, 13 Feb 1998 14:55:12 +0100


Matti J. Nykanen wrote:

> I have 2 questions for you experienced Clean users.

I have only one answer:
 
> 2. I am trying to implement a kind of  a "systolic array" algorithm in
> Clean, which would use in situ updates instead of copies, but I cannot
> get the uniqueness typing system to agree.  Could someone show how the
> following pseudo-Pascal algorithm is Cleaned?
> 
>         PROCEDURE systolic(
>                         VAR V:ARRAY[0..N] OF Boolean;
>                         I:0..N)
>                 BEGIN
>                 FOR J:=I TO N DO
>                         V[J]:=V[J] OR V[J-I]
>                 END;

Unfortunately, doing this with an array comprehension is rather hard, because
you want to do two selections on the same (unique) array, but a recursive
functions does the job:

systolic :: *{ #Bool } Int -> *{ #Bool }
systolic v i = systolic_ i v
where
   systolic_ j v
      | j == n    = v
      | otherwise =
         let!
            v_j  = v.[j]
            v_ji = v.[j - i]
         in
            systolic_ (j + 1) {v & [j] = v_j || v_ji }

(Of course, you have to define n somewhere)

This works, because the selections are done with observation types. The type
checker can see that if a selection is done in a strict context (the let!..in)
then the array will not loose its unicity.


> In other words, the datum V[J] reads the  datum V[J-I] I places to its
> left, performs an  OR, and passes  the result into  the datum V[J+I] I
> places to its right (if any) as well.

The program code says that the result datum is placed in V[J] again...  

Yours,
   Pascal Serrarens.