[clean-list] Re: relationship between uniqueness types and single-threaded lambda calculus?

lethevert acatofearlgrey at ybb.ne.jp
Sun Jun 3 11:26:37 MEST 2007


Hello Adam,


Adam Megacz wrote:
> I believe that in Clean, one would need to replace "lookup" with
> "uselect" to get the correct behavior.  However, the resulting program
> would no longer be type-correct -- "uselect" returns a pair.  So the
> program would need to be changed to "thread" the array through the
> lookups, somewhat like this:
> 
>  swap a i j
>  	#! (x,a1) = uselect a  i
>  	#! (y,a2) = uselect a1 j
>  	= update! (update! a2 i y) j x
> 
> Note that this increases the degree of sequentialization in the code
> (ie removes potential parallelism).  I believe that this threading is
> not necessary in STPLC.  So although #! and let* have similar
> meanings, STPLC can use let* in a way which does not appear to have an
> analogue in Clean (using #!).

If you are concerned about parallelism, how about introducing a new primitive
function such as:

swap a i j
     # (res, a) = uselectPar a [i,j]
     = update! (update! a i res.[1]) j res.[0]

The 'uselectPar' function takes an array and a list of array index, and returns
an array of selected values and the array.


If you are worried it is notationally cumbersome (which is more important for me)
I think it is better to make a new syntactic sugar such as do-notation in Haskell.

For exsample, the code

swap a i j
     = with a do
         x <- uselect i
         y <- uselect j
         update! i y
         update! j x

is translated into

swap a i j
     # (x,a) = uselect a i
       (y,a) = uselect a j
       a = update! a i y
       a = update! a j x
     = a


-- 
lethevert
lethevert at users.sourceforge.net


More information about the clean-list mailing list