[mercury-users] Some more Queries

Nancy Mazur Nancy.Mazur at cs.kuleuven.ac.be
Fri Nov 8 02:33:38 AEDT 2002


* Noel  Pinto <cool4life at rediffmail.com> [2002-11-07 15:07]:
> 
> 
> On Thu, 07 Nov 2002 Nancy Mazur wrote :
> >main -->
> >	io__open_input("blabla.txt", Result),
> >	(
> >		{ Result = ok(Stream) }
> >	->
> >		% then we could successfully open the file...
> >		% so here you can use Stream
> >		io__read(Stream, Input), ...
> 
> At this line it tells me that it says,

Don't tell me you have taken my example program as is? including the
"..." ? 

> test2.m:015: In clause for predicate `test2:main/2':
> test2.m:015:   in argument 1 of call to predicate `io:read/4':
> test2.m:015:   type error: variable `Stream' has type 
> `(io:output_stream)',
> test2.m:015:   expected type was `(io:input_stream)'.

are you sure you have used the predicate io__open_input, and not
io__open_output... because of course, in that case you have a type
mismatch.. 

> 
> >	;
> >		% or else something has gone wrong
> >		{ Result = error(Error) }
> >	->
> 
> At this line I get an  error which tells me to remove it, becuase 
> it does not have ';'

yeah, true... it should be followed by a last "else" case... but with
empty, or near to empty body... 

Here is a full bit of code... 

%-----------------------------------------------------------------------------
:- module test. 

:- interface.

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

:- implementation. 

main --> 
	io__open_input("blabla.txt", Result), 
	(
		{ Result = ok(Stream) }
	-> 
		io__read_char(Stream, Input), 
		(
			{ Input = ok(Char) }
		-> 
			io__write_string("First character = "), 
			io__write_char(Char), io__nl
		; 
			{ Input = eof }
		->
			io__write_string("End of File.\n")
		; 
			% or else Input = error(_, _)
			io__write_string("Error occurred.\n")
		)
	; 
		{ Result = error(Error) }
	-> 
		{ io__error_message(Error, ErrorMsg) }, 
		io__write_string("Error occurred: "), 
		io__write_string(ErrorMsg)
	; 
		[]
	). 

%-----------------------------------------------------------------------------

Ciao, 
Nancy
--------------------------------------------------------------------------
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