[m-dev.] Minimal streams diff
Fergus Henderson
fjh at cs.mu.OZ.AU
Wed Oct 2 12:43:03 AEST 2002
A couple of quick comments:
- what is the rationale for this change?
- how does this differ from Peter Ross's stream stuff
(which I think lives in extras/stream)?
On 02-Oct-2002, Michael Day <mikeday at yeslogic.com> wrote:
>
> Seeing as how Fergus has just announced a feature freeze, it seems like a
> good time to post a minimal streams diff for the day after the next
> release staggers out the door.
>
> I've tried to keep it to the minimum level of changes necessary to
> introduce stream type classes into the standard library, so it doesn't
> include putback streams or line number counting or anything like that.
>
> Interestingly enough, I ended up implementing socket streams on top of the
> posix code for the ICFP contest and they worked pretty well, but the lack
> of integration with regular io streams and the incredible irritation of
> having to manipulate separate io__result and stream__result types is a
> killer for any real usage.
>
> Anyway, anyone not busy frantically squashing bugs for the release, please
> feel free to criticise the diff below.
>
> Michael
>
> --- ../mercury-compiler-rotd-2002-09-07/library/io.m Thu Jul 25 02:05:11 2002
> +++ io.m Wed Oct 2 11:47:33 2002
> @@ -112,6 +112,43 @@
> ; end
> .
>
> +% Type classes
> +
> +:- typeclass input(S) where
> + [
> + pred input_stream_name(S, string, io, io),
> + mode input_stream_name(in, out, di, uo) is det,
> +% Retrieves the human-readable name associated with the
> +% specified input stream.
> +% For file streams, this is the filename.
> +% For stdin this is the string "<standard input>".
> +
> + pred read_char(S, io__result(char), io, io),
> + mode read_char(in, out, di, uo) is det
> +% Reads a character from specified stream.
> + ].
> +
> +:- instance input(input_stream).
> +
> +:- typeclass output(S) where
> + [
> + pred output_stream_name(S, string, io, io),
> + mode output_stream_name(in, out, di, uo) is det,
> +% Retrieves the human-readable name associated with the
> +% specified stream.
> +% For file streams, this is the filename.
> +% For stdout this is the string "<standard output>".
> +% For stderr this is the string "<standard error>".
> +
> + pred write_char(S, char, io, io),
> + mode write_char(in, in, di, uo) is det
> +% Writes a character to the specified output stream.
> + ].
Why not have the stream_name predicate in a base class inherited from
both input and output?
Wouldn't it be better to name the classes input_stream and output_stream?
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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