Question about uniqueness typing in Clean
ptg@owlnet.rice.edu
ptg@owlnet.rice.edu
Thu, 18 Apr 1996 10:48:41 -0500 (CDT)
>
> I have a question about uniqueness typing in Clean
>
> I want to simulate a dual-port RAM, that can read and write at the same clock
> cycle. So I tried to define a function 'ReadWrite', like follows:
>
>
> ::RAM:=={:Int:}
>
> ReadWrite::*RAM Int Int Int -> (*RAM,Int)
> ReadWrite ram readAdress writeAdress writeValue
> =let! readValue=ram.[readAdress]
This let! is the problem. In the Clean1.0.3 release let! does not handle
observing references properly. Pattern matching works, though.
> 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 ?
>
>
Try the following:
---
module blah
import StdEnv
::RAM:=={:Int:}
ReadWrite::*RAM Int Int Int -> (*RAM,Int)
ReadWrite ram=:{:[readAddress] = readValue:} readAddress writeAddress writeValue
= ({: ram & [writeAddress] = writeValue :}, readValue)
Start = ReadWrite (createArray 1 4711) 0 0 1996
---
Paul