[mercury-users] design of stream library

Peter Ross peter.ross at miscrit.be
Mon Sep 4 20:51:41 AEDT 2000


I have been playing with streams again, and have encountered a few
problems.  The current output stream design is as follows

:- typeclass stream__output(S) where [
    pred write_char(char::in, S::di, S::uo) is det
].

However this doesn't interact well with exceptions.  Say you have a bit
of code which outputs to a stream but might throw an exception, you wrap
it in an exception handler and you then want to clean up the stream, but
you no longer have a handle with which to refer to the stream.

Thus a stream should consist of two parts, a handle to the stream which
can be used for meta operations on a stream, and some sort of di/uo
pair.

:- typeclass stream__output(S) where [
    pred write_char(S::in, char::in, stream(S)::di, stream(S)::uo) is det
].

The problem with this design is that it doesn't work very well with
strings.  Under the old design you could write:

    write_char('x', "initial string", String)

but now you would need something like:

    string_stream_init("initial string", Handle, Stream),
    write_char(Handle, 'x', Stream0, Stream),
    get_string_from_string_stream(Hanlde, Stream, String)

which isn't very nice.

Does anyone else have any thoughts on the subject?

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