[mercury-users] uniqueness
Robert Ernst Johann JESCHOFNIK
rejj at cat.cs.mu.OZ.AU
Mon Oct 4 01:12:05 AEST 1999
On Mon, 4 Oct 1999, Fergus Henderson wrote:
> Currently we don't support nested unique modes.
Damn.
Just out of curiosity, how far away are they, roughly?
> When we support nested unique modes, then the object that you deconstruct
> would need to have the following inst
>
> :- inst uniq_f_matrix = unique(f_matrix(ground, ground, uniq_array(ground))).
>
> in order for the array__set call to work.
Well, I spent a bit of time playing (fighting) with my code before I
received/read your reply, and I had managed to come up with the following
code:
:- inst uniq_f_matrix(I, J, K) = unique(f_matrix(I, J, K)).
:- inst uniq_f_matrix == uniq_f_matrix(ground, ground, uniq_array).
:- mode f_matrix_di == di(uniq_f_matrix).
:- mode f_matrix_uo == out(uniq_f_matrix).
:- mode f_matrix_ui == in(uniq_f_matrix).
:- type f_matrix --->
f_matrix(
int, % M
int, % N
array(float) % the elements of the matrix
).
and the compiler does not give me any errors or warnings. Infact, I have a
predicate defined as follows:
:- pred f_matrix_set(int, int, float, f_matrix, f_matrix).
:- mode f_matrix_set(in, in, in, f_matrix_di, f_matrix_uo) is det.
f_matrix_set(I, J, Val, M_in, M_out) :-
M_in = f_matrix(M, N, Array0),
Location = I * N + J,
array__set(Array0, Location, Val, Array),
M_out = f_matrix(M, N, Array).
and it seems to be working. Before I got all the insts right, I was
getting uniqueness warnings here.
I wrote most of that inst code without having any idea really what I was
doing... It was more a case of copying style/syntax from declarations I
see in the library modules; but, having done it, I think I actually get
the drift of what is going on as I read back over it. (Although, I am
still not sure why the f_matrix(I, J, K) line is needed, and similarly
unsure why you can only use type variables in it.)
Am I correct in saying that the above code only works because of the
work-around in the array library, where uniq_array isn't really a unique
inst, but bound instead?
I think it is all slowly starting to fall into place...
thanks for your help, Fergus. especially since it is so late at night.
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