[mercury-users] odd warning..
Fergus Henderson
fjh at cs.mu.OZ.AU
Wed Sep 22 04:43:57 AEST 1999
On 22-Sep-1999, Rob <zharradan at suffering.org> wrote:
> I am getting a warning from the compiler that I have no idea how to go
> about fixing.. so I thought I would share with you to see if anyone can
> help :)
Juergen Stuber already answered your question.
I have just a few small comments to add.
> in handle_input.err:
> handle_input.m:043: In predicate `handle_input:convert_to_float/2':
> handle_input.m:043: warning: unresolved polymorphism.
> handle_input.m:043: The variable with an unbound type was:
> handle_input.m:043: V_7 :: T
> handle_input.m:043: The unbound type variable(s) will be implicitly
> handle_input.m:043: bound to the builtin type `void'.
Whenever you get a confusing error or warning message, try compiling
with `-E' (a.k.a. `--verbose-errors'). If you had compiled with `-E',
then the compiler would have offered the following additional information:
| The body of the clause contains a call to a polymorphic predicate,
| but I can't determine which version should be called,
| because the type variables listed above didn't get bound.
| (I ought to tell you which call caused the problem, but I'm afraid
| you'll have to work it out yourself. My apologies.)
> in handle_input.m, lines 43 & 44:
> :- pred convert_to_float(list(char), float).
> :- mode convert_to_float(in, out) is det.
>
> I assume the problem is coming from the fact that I use this predicate
> as a higher order constant in the following predicate:
> :- pred check_io_result(io__result(list(char)), pred(T),
> pred(list(char),T), T).
No, whenever the compiler says "In predicate foo, ...",
then the error will be an error in the definition of foo,
i.e. some inconsistency between foo and the things that foo calls,
not an inconsistency between foo and something that calls foo.
In contrast, the line numbers are less trustworthy; for example, if the
compiler knows only that the problem occurs somewhere in the
predicate body, then it may use the line number of the `:- pred'
declaration.
> % Display an error message due to invalid input, and terminate execution
> % This predicate has an (unused) output so that it can be used as an
> % EOF_Handler in check_io_result/4
> display_error(_) :-
> error("Invalid line in scene description").
>
> % Convert a list of characters to a float
> convert_to_float(Word, F) :-
> string__from_char_list(Word, S_F),
> (
> string__to_float(S_F, F0) ->
> F = F0
> ;
> % Bind F to something, to keep the compiler happy
> F = 0.0,
> display_error(_)
> ).
An alternative way of keeping the compiler happy here would be to write
the code as follows:
% This predicate has an (unused) output so that it can be used as an
% EOF_Handler in check_io_result/4
display_error_handler(_) :- display_error.
% Display an error message due to invalid input,
% and terminate execution
:- pred display_error is erroneous.
display_error :-
error("Invalid line in scene description").
convert_to_float(Word, F) :-
string__from_char_list(Word, S_F),
(
string__to_float(S_F, F0)
->
F = F0
;
display_error
).
Note that because `display_error' is declared to have determinism `erroneous',
meaning that it will never return, the compiler knows that you don't need
to bind `F' in that branch.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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