

On Sun, 10 Nov 2002 Ralph Becket wrote :
... ...
>Now your problem is that in the third arm of the switch, you (a) 
>haven't
>put the test first, which unfortunately does matter in this case, 
>and
>(b) you haven't put parentheses around the if-then-else there, so 
>the
>compiler thinks that the call to io__write_string is part of 
>the
>if-then-else condition, which is wrong because the condition can 
>fail
>and io__write_string has unique arguments, and (c) you don't need 
>an
>if-then-else there at all.  Here's how the last part should 
>look:
>
> > 			{ ResStr = error(Err1)},
> > 			io__write_string(" Error occured.\n"),
> > 			{ io__error_message(Err1, ErrMesg)},
> > 			io__write_string(ErrMesg)
>

I did follow your suggestions and wrote the code as below...
:- module test3.

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

:- implementation.

main -->
 	io__open_binary_input("blah.txt", Res),
 	(
 		{ Res = ok(Str)}
 	->
 		io__read_binary(Str, ResStr `with_type` io__result(string)),
 		(
 			{ResStr = ok(Binr `with_type` string)}
 		->
 			io__write_string(" Binary representation of a term is : "),
 			io__write_binary(Binr `with_type` string), nl
 		;
 			( { ResStr = eof }
 		->
 			io__write_string(" End of File.\n")
 		;
 			{ ResStr = error(Err1)},
 			io__write_string(" Error occured.\n"), % I am getting error 
over here
 			{ io__error_message(Err1, ErrMesg)},
 			io__write_string(ErrMesg) )% I have added these round brackets 
because without them an error occurs.
 		)
 	;
 		{ Res = error(Err)}
 		->
 		{ io__error_message(Err, ErrMsg)},
 		io__write_string("Error occured: "),
 		io__write_string(ErrMsg)
 		;
 		[]
 	).

I have get an error... I am totatlly confused as to how to proceed 
further. The error is...
test3.m:005: In `main(di, uo)':
test3.m:005:   error: determinism declaration not satisfied.
test3.m:005:   Declared `det', inferred `semidet'.
test3.m:025:   Unification of `ResStr' and `io:error(Err1)' can 
fail.
For more information, try recompiling with `-E'.

--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users@cs.mu.oz.au
administrative address: owner-mercury-users@cs.mu.oz.au
unsubscribe: Address: mercury-users-request@cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request@cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------

