[m-users.] determinism declaration of main as "erroneous"

Julien Fischer jfischer at opturion.com
Tue Oct 29 20:21:47 AEDT 2019


On Tue, 29 Oct 2019, Volker Wysk wrote:

> This program compiles:
>
> :- module test_format.
> :- interface.
> :- import_module io.
> :- pred main(io::di, io::uo) is det.
>
> :- implementation.
> :- import_module exception, list, string.
>
> main(!IO) :-
>    throw("bla").
>
>
> But I get this warning message:
>
> test_format.m:004: In `main'(di, uo):
> test_format.m:004:   warning: determinism declaration could be tighter.
> test_format.m:004:   Declared `det', inferred `erroneous'.
>
> When I replace "det" by "erroneous", I get:
>
> test_format.m:004: Error: `main'/2 must be `det' or `cc_multi'.
> ** Error making `Mercury/cs/test_format.c'.
>
> So the warning message is wrong. A little bug.

The warning is just the standard one that determinism analysis generates
for any predicate where the determinism could be tighter.  (That warning
doesn't consider main/2 to be a special case.)  The check implemented by
the error message is specific to main/2.  The wording of the warning is
a bit off in this particular case, but the warning still has value; in
most circumstances having a main prediate that is erroneous is likely a
bug.

Speaking of which, why do you have program that does nothing but throw
an exception?  You could always avoid the warning by writing it as:

     main(!IO) :-
         ( if semidet_true then
             throw("bla")
         else
             true
         ).

Julien.


More information about the users mailing list