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

Adam Megacz megacz at cs.berkeley.edu
Mon Jun 4 16:57:57 MEST 2007


Edsko, thank you again for your patience in explaining this to me.

Edsko de Vries <devriese at cs.tcd.ie> writes:
>   (1) The arr is assumed non-unique within the let* block, and
>   (2) The definitions in the let* block must be evaluated before the body

Ah, this definitely helps a lot.  By the way, is there any
documentation of #! more detailed than the Clean 2.1 report?  The
report doesn't mention these aspects, though I think it would have
helped a lot if it did.

> selectx :: {Int} Int -> StrictPair Int

Thank you once again!

One more question, however.  Why does the compiler complain when I
change selectx to this?

  selectx :: {Int} Int -> StrictPair {Int}
  selectx x y = Sp (select x y) {1,2}

Does the compiler somehow use the knowledge that "a (StrictPair Int)
cannot contain references to an {Int}" to reason about uniqueness?
That would explain why it doesn't like the version of selectx which
returns an (unrelated) {Int} as part of its result.

  - a

(for convenience, here is the complete program)
..............................................................................
module SwapExample

import StdEnv

// just to make sure that no auto-tuple-strictification is going on
::StrictPair a = Sp !Int !a
strictPairFst :: (StrictPair a) -> Int
strictPairFst (Sp x y) = x

// returns a strict pair (a[i],i)
selectx :: {Int} Int -> StrictPair {Int}
selectx x y = Sp (select x y) {1,2}

// this works
swap :: *{Int} Int Int -> *{Int}
swap arr i j
    #! 
//       a = Sp (select arr i) i
       a = selectx arr i
       b = select arr j
    = (update (update arr i b) j (strictPairFst a))


Start = swap {1,2,3,4,5} 2 3






More information about the clean-list mailing list