[mercury-users] Puzzled about about I/O in predicates which may fail

Ralph Becket rafe at cs.mu.OZ.AU
Wed Nov 24 13:55:12 AEDT 2004


Gregory D. Weber, Tuesday, 23 November 2004:
> It seems to me that by using state variables, I can "fix" an
> error involving I/O in predicates which may fail.
> If read_problem_decl_semidet is indeed semidet, then
> 
> (EXAMPLE 1)
> 
> main(!IO) :-
> 	(
> 	  read_problem_decl_semidet("credit.decl", Problem, !IO) ->
> 	  describe_problem(Problem, !IO)
> 	;
> 	  io__print("Error reading file\n", !IO)
> 	).
> 
> compiles without any error message.  Moreover, running the program
> actually works!

Which version of the Mercury compiler are you using?  I just tried to
compiler the following module using a recent ROTD:

:- module foo.
:- interface.
:- import_module io.

:- pred main(io :: di, io :: uo) is det.

:- implementation.
:- import_module std_util, string.

main(!IO) :-
    ( if p(!IO) then io.print("yes\n", !IO) else io.print("no\n", !IO) ).


:- pred p(io::di, io::uo) is semidet.

p(!IO) :-
    semidet_succeed.

and obtained the following (correct) error message:

Making Mercury/int3s/foo.int3
Making Mercury/cs/foo.c
foo.m:014: In `p(di, uo)':
foo.m:014:   error: invalid determinism for a predicate with I/O state
foo.m:014:   arguments.
foo.m:011: In clause for `main(di, uo)':
foo.m:011:   in argument 1 of call to predicate `foo.p/2':
foo.m:011:   mode error: variable `STATE_VARIABLE_IO_0' has instantiatedness `mostly_unique',
foo.m:011:   expected instantiatedness was `unique'.
For more information, try recompiling with `-E'.
** Error making `Mercury/cs/foo.c'.

-- Ralph
--------------------------------------------------------------------------
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