[mercury-users] Uniqueness and store.m
Mark Brown
mark at cs.mu.OZ.AU
Sat Dec 31 00:03:08 AEDT 2005
Hi Sergey,
On 30-Dec-2005, Sergey Khorev <iamphet at nm.ru> wrote:
> I'm trying to figure out how to use store.m and ran into problems with storing types that contain references.
> The compiler version 0.12.1 gives me an error
> sto2.m:024: In clause for `main(di, uo)':
> sto2.m:024: in argument 1 of call to predicate `store.new_ref/4':
> sto2.m:024: mode error: variable `V_18' has instantiatedness `unique(sto2.p(ground, ground))',
> sto2.m:024: expected instantiatedness was `unique'.
>
> I can't understand where this constraint has arisen from.
Unfortunately, you've encountered a bug in unique mode analysis (which is
probably related to the known limitations -- see section 5.3 of the
reference manual).
You can generally work around this by using unsafe_promise_unique; of course,
you have to be careful that you don't make a promise that isn't true. For
example, you can replace the last line with:
unsafe_promise_unique(p(Rn, Rs), P)
new_ref(P, _Rp, S2, _S3).
> Is it possible to keep store__references in the store at all?
Using the above technique will get your existing code to compile. However,
the "references" section of the store module isn't designed to do what I think
you are intending to do, so you will run into problems if you try to actually
use the reference you create. In particular, notice that if you use
extract_ref_value to dereference Rp then the store will be destroyed and
you won't be able to do anything with Rn and Rs anyway. You could probably
get away with using copy_ref_value, but I imagine you want to avoid doing a
deep copy of your data (which is what copy_ref_value is _meant_ to do -- the
fact that it only does a shallow copy in the current implementation could
also cause problems).
The references interface is mainly useful for hand implementing destructive
update, AFAIK. For what I think you are trying to do, it would be better to
use the mutvars interface.
Cheers,
Mark.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list