[mercury-users] Re: (the lack of) unique modes
Robert Ernst Johann JESCHOFNIK
rejj at cat.cs.mu.OZ.AU
Fri Nov 5 14:54:10 AEDT 1999
On Fri, 5 Nov 1999, Fergus Henderson wrote:
> Or you could try using `array' and using
> `unsafe_promise_unique' (in the `builtin' standard library module)
> to work around the cases where the compiler's uniqueness analysis is
> overly conservative.
As I understand it, unsafe_promise_unique/2 gives back an object with
instantiatedness `unique', and this will cause mode errors with things
like array__set, that expect something else, for example, `uniq_array'.
I had this problem with the graphics assignment I recently did, and I
believe Ralph recently banged his head against the same problem as well.
Luckily, I happened to be in the right place at the right time (4pm the
day the assignment was due) and caught Tom Conway in a hallway, and he
provided a workaround. I believe I sent this to Ralph in an email a few
weeks ago, but it is short, so here it is again.
:- func u(array(T)) = array(T).
:- mode (u(in) = array_uo) is det.
:- pragma c_code(u(A::in) = (B::array_uo),
[will_not_call_mercury, thread_safe],
"B = A;"
).
So I guess you could use (something very similar to) this to solve your
map woes, Tomas. Just make some custom :- inst's for your types, and then
modes (a_uo, a_di, etc) that use them, and inside a call, use the above
function to ensure uniqueness.
eg,
(assuming `C' is a 2d array or higher, and do_something/2 uses destructive
update on the array it is given)
array__lookup(C, Pos, Element),
do_something(u(Element), NewElement),
...
heh. I think I have finally got my head around uniqueness now. :)
Rob
--------------------------------------------------------------------------
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