The Standard ML Basis Library


The StreamIO functor

The optional StreamIO functor provides a way to build a stream IO stack on top of an arbitrary primitive I/O implementation. For example, given an implementation of readers and writers for pairs of integers, one can define streams of pairs of integers.


Synopsis

functor StreamIO ( ... ) : STREAM_IO

Functor argument interface

structure PrimIO : PRIM_IO
structure Vector : MONO_VECTOR
structure Array : MONO_ARRAY
sharing type PrimIO.elem = Vector.elem = Array.elem
sharing type PrimIO.vector = Vector.vector = Array.vector
sharing type PrimIO.array = Array.array
val someElem : PrimIO.elem

Description

structure PrimIO
This is the underlying primitive I/O structure.

structure Vector

structure Array

sharing type PrimIO.elem
sharing type PrimIO.vector
sharing type PrimIO.array

someElem
is some arbitrary element used to initialize buffer arrays.


Discussion

The Vector and Array structures provide vector and array operations for manipulating the vectors and arrays used in PrimIO and StreamIO. The element someElem is used to initialize buffer arrays; any element will do.

The types instream and outstream in the result of the StreamIO functor must be abstract.

If flushOut finds that it can do only a partial write (i.e., writeVec or a similar function returns a ``number of elements written'' less than its sz argument), then flushOut must adjust its buffer for the items written and then try again. If the first or any successive write attempt returns zero elements written (or raises an exception) then flushOut raises the IO.Io exception.

If an exception occurs during any stream I/O operation, then the module must, of course, leave itself in a consistent state, without losing or duplicating data.

In some ML systems, a user interrupt aborts execution and returns control to a top-level prompt, without raising any exception that the current execution can handle. It may be the case that some information must be lost or duplicated. Data (input or output) must never be duplicated, but may be lost. This can be accomplished without stream I/O doing any explicit masking of interrupts or locking. On output, the internal state (saying how much has been written should be updated before doing the write operation; on input, the read should be done before updating the count of valid characters in the buffer.

Implementation note:

Here are some suggestions for efficient performance:

See Also

STREAM_IO

[ INDEX | TOP | Parent | Root ]

Last Modified May 10, 1996
Comments to John Reppy.
Copyright © 1997 Bell Labs, Lucent Technologies