[clean-list] questions about uniqueness

Arjen van Weelden A.vanWeelden at cs.ru.nl
Tue Oct 18 09:08:08 MEST 2005


Hi,

Valery wrote:
> I'm a bit lost with uniqueness typing. Could anyone help me along ?
> 
> /1/
> Start = (a,f 1 a,f 2 a)
> where
>    f :: !Int *{#Int} -> *{#Int}
>    f i t
>    #! t0 = t.[0]
>    = {t & [0] = t0 + i}
> a :: *{#Int}
> a = {i \\ i <- [0..9]}
> The code above produces ({0,1,2},{1,1,2},{2,1,2}), as if 'a' was not 
> unique, but I expected it to be rejected by the compiler, because 'f' is 
> supposed to update its unique argument in place, that is, 'a' should be 
> destroyed by the first application of 'f, and the second one should fail.
> Where am I wrong ? Does 'f' duplicate its array argument despite the 
> uniqueness annotation ?
> 
a is a function, and returns a new unique array each time you call it.
Therefore, the function f is applied to a fresh unique array, different 
from the other arrays created by the function a.

> /2/
> What I want actually is a struct that contains a unique array, because 
> the array will be updated in place several time later. The struct itself 
> will be copied, not updated.
> When I try
> :: Pos = {t :: *{Int}}
> I get "inconsistent attribution of type definition", which is fine, 
> since whatever contains something unique has to be unique, but when I try
> :: Pos = *{t :: *{Int}}
> I get "} expected instead of ::".
> How to define this type ?
> 
You do it like this:

:: *Pos = {t :: *{Int}}

> Valery
> 
regards,
	Arjen


More information about the clean-list mailing list