[mercury-users] Hash_table initialization
Peter Moulder
pmoulder at mail.csse.monash.edu.au
Fri May 2 22:45:27 AEST 2003
On Fri, May 02, 2003 at 12:30:26PM +0100, Goncalo Jorge Coelho e Silva wrote:
> 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)'.
Change the mode of HashTable in lookup_label from `in' to `in(hash_table)'.
As the Modes section of the Mercury language reference manual notes:
# The standard library provides the parametric modes
#
# :- mode in(Inst) == Inst >> Inst.
# :- mode out(Inst) == free >> Inst.
so `in(hash_table)' means that HashTable has an initial instantiatedness
of `hashtable', as required to meet the requirements of elem.
(When the error message says `hash_table:hash_table', it's using a
deprecated form of module qualification, i.e. the instantiatedness
defined in the `hash_table' module and called `hash_table'. We could
have said `in(hash_table:hash_table)' or `in(hash_table__hash_table)'.)
This change is sufficient to make inter.m compile.
Btw, in its current form, you can get rid of the io__state arguments to
lookup_label, and use the normal non-DCG syntax:
:- pred lookup_label(hash_table(string, int), string, int).
:- mode lookup_label(in(hash_table), in, out) is det.
lookup_label(HashTable, Label, Index):-
Index = HashTable^elem(Label).
pjm.
--------------------------------------------------------------------------
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