[clean-list] uniqueness question

Carlos Aya carlosayam at yahoo.com.au
Tue Nov 17 02:13:40 MET 2009


Well, what I want to achieve is a more generic 'update in place' for arrays. For example, to implement something like "v1 += v2" for arrays.

My current attempt goes like this

-----------------------------------------------------------
. . .

addInPlace :: *(a e) .(b e) -> *(a e) | Array a e & Array b e
addInPlace arr1 arr2 = updateInPlace arr1 (\v p = v + arr2.[p]) (size arr2)

updateInPlace :: *(a e) .(e Int -> e) Int -> *(a e) | Array a e
updateInPlace arr1 f maxPos = updateLoop_ arr1 f 0 maxPos

updateLoop_ :: *(a e) .(e Int -> e) Int Int -> *(a e) | Array a e
updateLoop_ arr1 f pos maxPos
| pos == maxPos  = arr1
# (v, arr1) = arr1![pos]
= {(updateLoop_ arr1 f (pos+1) maxPos) & [pos] = f v pos} 

-----------------------------------------------------------

I am getting this error...

Overloading error [test1.icl,7,addInPlace]: internal overloading of "lambda [line 8]" could not be solved.

which probably displays my ignorance. [You get the idea, this should be a closure with arr2 inside, v comes from the actual value in arr1 at p. See functions below.]

But the funny thing is the error with updateLoop_, have a look...

Type error [test1.icl,13,updateLoop_]:derived type conflicts with specified type:
 *(a b) (b -> Int -> b) Int Int -> *(a b) | Array a b
 *(a b) .(b -> Int -> b) Int Int -> *(a b) | Array a b

The two types are identical BUT the function parameter (e Int -> e) has attribute any "." in my signature and _no_ attribute in the inferred type. If I change my signature and remove the uniqueness attribute for f [in updateLoop_ and updateInPlace], it passes. What's wrong here?

John, I read the paper and still don't get it.
Could you please provide an example? Also, it seems to suggest that the
types of
f :: *a .b -> *a
and
g :: .b *a -> *a
could be treated differently as in the last one only the last parameter
is unique and therefore there is no risk in creating a partial
application that violates single threaded semantics. Am I right? Is it
like that in Clean?

Kind regards
Carlos



--- Original Message ----
From: Edsko de Vries <edskodevries at gmail.com>
To: John van Groningen <johnvg at cs.ru.nl>
Cc: Carlos Aya <carlosayam at yahoo.com.au>; clean-list at cs.ru.nl
Sent: Tue, 17 November, 2009 3:05:34 AM
Subject: Re: [clean-list] uniqueness question

Hey,

On 16 Nov 2009, at 15:57, John van Groningen wrote:
> Carlos Aya wrote:
>> Does anyone know why the following type signature is invalid?
>> 
>> second :: *a .a -> *a
>> second x y = x
>> 
>> I am getting this message
>> Error [matrices.icl,12,second]: a inconsistently attributed (4)
> 
> The same uniqueness attribute must be used for all occurrences of
> a type variable in a function type.
> 
>> I came across this trying to type a more complex function with arrays, but it boils down to signature above.
>> Why the uniqueness attribute has to be the same for two independent parameters that just happen to have the same type?
> 
> A type '*a' cannot be coerced to 'a', because 'a' could be a partial
> application with a unique argument. It this were allowed the unique
> argument could be used more than once. Because the opposite coercion
> (from 'a' to '*a') is also not possible, the compiler requires that
> all occurences of a type variable have the same uniqueness attribute
> (as mentioned above).

While all of that is true, it still does not explain why all occurrences of a type variable need the same attribute. For instance, there is absolutely no problem with 

second :: *a .a -> *a
second x y = x

Edsko


      __________________________________________________________________________________
Get more done like never before with Yahoo!7 Mail.
Learn more: http://au.overview.mail.yahoo.com/



More information about the clean-list mailing list