[m-dev.] Bulk stream operations (was Re: [m-rev.] for review: bit buffers)
Ian MacLarty
maclarty at csse.unimelb.edu.au
Thu May 17 13:48:05 AEST 2007
On Wed, May 16, 2007 at 02:44:19PM +1000, Simon Taylor wrote:
> On 15-May-2007, Ian MacLarty <maclarty at csse.unimelb.edu.au> wrote:
> > On Mon, May 14, 2007 at 04:17:12PM +1000, Simon Taylor wrote:
> > > library/stream.m:
> > > Add classes bulk_writer and bulk_reader, which support
> > > reading and writing multiple items at once into a store.
> >
> > Can you explain why you have created a new typeclass and not used the existing
> > stream typeclasses? It should be possible to create a buffered bit stream
> > using a mutvar attached to the stream state.
>
> On reflection, bulk output could be done using an instance as below:
> :- type bitmap.slice ---> slice(bitmap, bit_index, num_bits).
> :- instance stream.writer(io.binary_output_stream, bitmap.slice, io).
>
> The reason for adding the bulk_writer class was to express the uniqueness of
> the input argument, but the loss of uniqueness of the input happens with
> other predicates like io.write anyway. I'll remove it.
>
Okay.
> Input is a bit more difficult. How can I efficiently read a block of
> bytes from a stream without defining a new class? Adding the bulk_reader
> class allows streams that support transfer of blocks of data to be used
> efficiently, while other streams can fill the block manually. Given
> that the most commonly used streams support block operations, it's
> important to handle those operations well.
>
Okay. I was confused about the interface in bit_buffer.read.m where you define
get_bit and get_byte. I suppose it would still be possible to layer a
stream.reader over this interface that reads bits and bytes, so that's okay
then.
> > One of the motivating reasons for parameterising readers and writers over the
> > unit type was so that both text and binary streams could be handled using the
> > same typeclass. If you define a new typeclass, then some reuse potential is
> > lost (for example you cannot use stream.input_stream_fold).
>
> I'm not sure what you mean; a stream can be an instance of both reader
> and bulk_reader.
Yes, you're right. And I suppose you could also layer a stream.reader on top
of a stream.bulk_reader if you wanted to use stream.input_stream_fold, etc.
Ian.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions: mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the developers
mailing list