[mercury-users] Hash_table initialization
Goncalo Jorge Coelho e Silva
l10454 at alunos.uevora.pt
Fri May 2 21:30:26 AEST 2003
Hi,
I had a problem while declaring a predicate signature
with an hash_table as an argument.
I think it has to do with a wrong hash_table argument fingerprint
declaration, in pred for lookup_label/5...
should it be 'hash_table(string, int)'? ... it seems not...
what then?
I tried this out:
:- module inter.
:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is det.
:- pred lookup_label(hash_table(string, int), string, int, io__state, io__state).
:- mode lookup_label(in, in, out, in, out) is det.
:- implementation.
:- import_module hash_table.
lookup_label(HashTable, Label, Index) -->
{
Index = HashTable^elem(Label)
}.
% same without DCGs
%lookup_label(HashTable, Label, Index, IO, IO):-
% Index = HashTable^elem(Label).
main(IO0,IO) :-
% create an empty hash table
HashTable0 = new_default(string_double_hash),
% insert a key and value into the hash table
%HashTable1 = det_insert(HashTable0, "some key", 42),
HashTable1 = ( HashTable0 ^ elem("some key") := 42),
% lookup a key in the hash table
N = HashTable1^elem("some key"),
% print the result
print("N = ", IO0, IO1),
print(N, IO1, IO2),
nl(IO2, IO).
Compilation result was:
inter.m:018: In clause for `lookup_label(in, in, out, in, out)':
inter.m:018: mode error in conjunction. The next 2 error messages
inter.m:018: indicate possible causes of this error.
inter.m:018: In clause for `lookup_label(in, in, out, in, out)':
inter.m:018: in argument 2 of call to function `hash_table:elem/2':
inter.m:018: mode error: variable `HashTable' has instantiatedness
`ground',
inter.m:018: expected instantiatedness was `(hash_table:hash_table)'.
inter.m:016: In clause for `lookup_label(in, in, out, in, out)':
inter.m:016: in argument 3 of clause head:
inter.m:016: mode error in unification of `HeadVar__3' and `Index'.
inter.m:016: Variable `HeadVar__3' has instantiatedness `free',
inter.m:016: variable `Index' has instantiatedness `free'.
make: *** [run] Error 1
Tips on what's wrong would be appreciated :)
Thanks again.
Cheers,
Goncalo
--------------------------------------------------------------------------
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