[m-dev.] streams proposal (part 2)
Ian MacLarty
maclarty at cs.mu.OZ.AU
Sat Feb 25 23:15:34 AEDT 2006
On 24 Feb 2006, at 03:05, Julien Fischer wrote:
>>
>>
>>> % Close the stream.
>>> % Throws an exception if there is an error while closing the
>>> stream.
>>> %
>>> pred close(Stream::in, State::di, State::uo) is det
>>> ].
>>>
>>
>> I don't think close should be a method of the typeclass. I think
>> different
>> stream types may require different close methods (with different
>> numbers
>> and/or types of arguments) or no close method at all.
>
> Can you provide an example?
>
Well suppose I have a stream that encrypts data and forwards it on
to some other stream. Does having a close method for such a stream
make sense? You don't want the close method for the encryption
stream to close the stream it's writing to, since you may want to
write some more unencrypted data to that stream after writing the
encrypted data.
Another example:
Suppose you have a stream for some network protocol that requires
that the host that's closing the connection send the other host some
kind of token to say why the connection is being closed. This
would require the close predicate to have an extra argument.
(You could also write the token before calling close, but it'd be
a better design to give close an extra argument to be sure the
required token is always written before closing).
>> Typically the operations of opening a stream and closing
>> a stream will go together and since we are not including opening of
>> streams in the typeclass I don't think we should include closing of
>> streams either.
>
> Yes, but that's because (under this model at least) you need an already
> open stream to invoke the typeclass methods upon - I don't see why
> close shouldn't be a typeclass method
>
I think having a close method will also create confusion about who is
supposed to close an opened stream. How do I know a call to some
predicate that accepts a stream argument will not close the stream?
If you don't have a close method then it is always the responsibility
of the opener of the stream to also close the stream and you avoid
the above confusion.
Ian.
--------------------------------------------------------------------------
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