[clean-list] questions about uniqueness
Peter Achten
P.Achten at cs.ru.nl
Tue Oct 18 08:56:43 MEST 2005
Dear Valery,
At 08:52 PM 10/17/2005, you 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 ?
The reason that you get three arrays is because a is a function that, when
evaluated, yields a unique array. If you would have used a locally within
f, then the code would have been rejected (don't forget to remove the type
of a, otherwise it will be regarded as a local function:
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]}
This correctly produces the error messages:
Uniqueness error [uniqueness_Valery.icl,5,Start]: "a" demanded attribute
cannot be offered by shared object
>/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 ?
Your analysis is correct: uniquely attributed objects must reside in unique
objects. This is indicated by attributing the type constructor as unique:
:: *Pos = { t :: *{Int}}
Regards,
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.science.ru.nl/pipermail/clean-list/attachments/20051018/2a0b4e6b/attachment.html
More information about the clean-list
mailing list