[mercury-users] Predicate call uses the "wrong" mode

Barney Fisher barney.fisher at googlemail.com
Wed Aug 8 03:00:44 AEST 2007


> I see a couple of options:
>
> Change nothing and very explicitly document the behavior.  This doesn't take
> much time but might confuse those that don't get that far in the
> documentation.
> Call using foo(in, in) an error if foo(in, out) and foo(out, in) are defined
> and foo(in, in) isn't explicitly defined.  This would break old code.  I
> wouldn't be surprised if it broke the compiler.  On the other hand, the fix
> is reasonably easy.
> From Nick:  Call it an error if foo(in, in) is not defined and both foo(in,
> out) and foo(out, in) are defined.  This has the advantage of catching the
> situation early but it may generate more errors and code then is needed.
> #2 but substitute the word warning for error and default using the order in
> the file, the overall mode (probably the wrong term, what I mean is det,
> semidet, multi, nondet, etc), or something else.
>  #3 but substitute the word warning for error and default using the order in
> the file, the overall mode, or something else.
> Default using the overall mode ala Peter.
> Any other ideas?
>
> --Nik

I think at least a warning message should be produced by the compiler
when using an implied mode.

The problem I had was that I was converting some Prolog code to
Mercury where each predicate was called in many different ways.  Under
these circumstances, it is very time consuming and error-prone to
check that there is a mode declaration for each way a predicate can be
called.  My first stab at the mode declarations gave something that
compiled but ran very slowly.  Then throughout debugging I encountered
solely implied mode problems.  There were a few cases where implied
modes were being used when there was no explicit mode available.  This
was because I hadn't anticipated that the predicate would be called in
that manner; thus, an error with the mode declarations and my
understanding.  The other case was when an explicit mode existed but
was written after an implied mode; thus, a lack of understanding of
the Mercury implementation.  Both these cases are down to programmer
error so therefore a warning message would be appropriate.  Obviously,
it shouldn't be an error message because implied modes are useful in
some cases!

In terms of execution speed this is an important matter, at least for
the code I was using, because the 'first stab' executable took ~17
seconds to execute, but the final 'fully explicit mode' version took
~0.5 seconds.  Quite a big improvement.

Barney
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list