[m-dev.] Minimal streams diff

Ralph Becket rafe at cs.mu.OZ.AU
Thu Oct 3 11:33:05 AEST 2002


Michael Day, Thursday,  3 October 2002:
> 
> How to make an instance of stream for stdin, when stdin is just a 
> particular input_stream returned by stdin_stream?

My thought was to reproduce much of the io module functionality for
streams, but to type specialize the stream-based operations for
std{in,out,err}.  This way we get good stream-based performance for
ordinary IO.

> If by bulk IO you mean writing out an array of characters at a time, that
> can happen below the stream interface, in its implementation. The stream
> implementations I am using buffer characters until the buffer is full (or
> flush_output is called) and then write them all out at once, and the input
> stream implementation performs read ahead. Does that need to be in the
> interface, though?

I could write a predicate called write_char_array_to_stream that just
wrote out each array member in turn, but that would mean pointlessly
copying the data before writing it.  There are situations where this
makes a difference (e.g. web servers.)

As an aside, it's probably not a great idea to do buffering at the
Mercury level because that's almost certainly handled by the underlying
IO mechanisms on the target platform.

> I use streams as if they are byte streams, as that's practically what they
> are on unix at least.

Yes, but we don't have nearly the same degree of control over them in
Mercury.  For instance, we have no interface to turn buffering and
blocking on and off, or to indicate the amount of buffering.

> > (Admittedly, generalising away from char will probably require
> > a more powerful type class scheme.)
> 
> s/probably/definitely/ :)

Indeed!

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