[m-dev.] for discussion: stream library v2

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Sep 29 21:30:06 AEDT 2000


On 29-Sep-2000, Michael Day <mcda at students.cs.mu.oz.au> wrote:
> 
> > If you need to do that, then you might as well just provide a
> > higher-order `with_stream' procedure rather than providing `open' and
> > `close', so that programmers don't need to rewrite that exception
> > handling code each time.  And once you do that, then you don't
> > actually need the extra parameter to the io__state type.
> > 
> > 	:- pred with_stream(pred(stream(S)::di, stream(S)::uo),
> >                 io__state::di, io__state::uo).
> 
> How would this predicate be used exactly?

I missed out some details, which probably made it confusing.
`with_stream' needs some extra parameters -- the same ones
passed to `open'.  Where in the current system we have lots
of different versions of `open', in this version you'd need
lots of different version of `with_stream'.

Then

	main -->
		with_stream(..., (pred(di, uo) is det -->
			write_char('x')
		).

would have the effect of

	(1) opening a stream (using the file name or whatever other
	    parameters are specified in the "..."); and then

	(2) invoking the lambda expression that was passed as argument
	    to with_stream, passing it the stream that was opened in
	    (1); and finally

	(3) when the lambda expression exits (whether by returning or
	    by throwing an exception), close the stream

	(4) if the lambda expression exited by throwing, rethrow the
	    exception

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list