Question about uniqueness typing in Clean

Jan Krynicky JKRY3025@barbora.mff.cuni.cz
Thu, 18 Apr 1996 18:00:51 +0200


> 
> I have a question about uniqueness typing in Clean
> 
> 
> ::RAM:=={:Int:}
> 
> ReadWrite::*RAM Int        Int         Int         -> (*RAM,Int)
> ReadWrite   ram readAdress writeAdress writeValue 
>    =let! readValue=ram.[readAdress]
>     in   ( {:ram & [writeAdress]=writeValue:},
>            readValue)
> 
> Start=ReadWrite (createArray 1 4711) 0 0 1996
> 
> 
> ReadWrite returns the updated RAM and the read value.
> The Compiler reports 'conflicting uniqueness information due to argument 1 of 
> _update'.
> I'm just beginning using uniqeness typing. Maybe the problem is, that the 
> second argument of the result (the read value) contains a reference into the 
> first argument (the unique array, that represents the RAM). Could I solve the 
> problem by somehow COPYING an element out of the array, so that there is no 
> need for a reference ? Or is there any other solution ?
> 
> 
This should do, though it's not very nice

ReadWrite   ram readAdress writeAdress writeValue
   =( {:ram` & [writeAdress]=writeValue:}, readValue)
 where
  (readValue, ram`) = uselect ram readAdress

Your solution could work, cause the Int (readValue) can't contain
any reference to ram since it is fully evaluated.
I think that I've read somewhere that they plan such analysis
(the let! construct itself is not enough, you must look at the type 
too.) but it's not completed or something.

Anyway the functions uselect and usize can be used instead.

Hi, Jenda