[m-rev.] diff/for review: remove error type as a paramter of stream.input

Julien Fischer juliensf at csse.unimelb.edu.au
Fri Apr 20 16:35:41 AEST 2007


The following diff will break existing code in a fairly minor way;
the fix is just to delete the error parameter from any stream.input
instances.

Estimated hours taken: 1
Branches: main

Make the stream error type specific to each reader, not specific to an entire
input stream.  This means that different readers attached to the same stream
can return different types of error; this is useful in the case where a
reader can return a partial result.

library/stream.m:
 	Change the definition of input streams so that they no longer include
 	parameter for the error type.

 	Introduce the error type as a parameter of the reader class.
 	This means that different readers attached to the same stream may
 	now have different error types.  The error type is functionally
 	dependent upon the reader's handle and unit types.

library/io.m:
extras/net/tcp.m:
 	Conform to the above change.

Julien.

Index: extras/net/tcp.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/net/tcp.m,v
retrieving revision 1.4
diff -u -r1.4 tcp.m
--- extras/net/tcp.m	20 Apr 2007 00:48:50 -0000	1.4
+++ extras/net/tcp.m	20 Apr 2007 06:06:55 -0000
@@ -56,7 +56,7 @@
  :- instance stream(tcp, io.state).
  :- instance error(tcp.error).

-:- instance input(tcp, io.state, tcp.error).
+:- instance input(tcp, io.state).
  :- instance reader(tcp, character, io.state, tcp.error).
  :- instance reader(tcp, line, io.state, tcp.error).

@@ -392,7 +392,7 @@
  		get_error(E, S)
  	)
  ].
-:- instance input(tcp, io.state, tcp.error) where [].
+:- instance input(tcp, io.state) where [].
  :- instance reader(tcp, character, io.state, tcp.error) where [
  	(get(T, Result, !IO) :-
  		tcp__read_char(T ^ handle, Char, !IO),
Index: library/io.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.380
diff -u -r1.380 io.m
--- library/io.m	20 Apr 2007 00:48:50 -0000	1.380
+++ library/io.m	20 Apr 2007 06:06:55 -0000
@@ -1461,7 +1461,7 @@
  :- instance stream.line_oriented(io.output_stream, io).

  :- instance stream.stream(io.input_stream, io).
-:- instance stream.input(io.input_stream, io, io.error).
+:- instance stream.input(io.input_stream, io).
  :- instance stream.reader(io.input_stream, char, io, io.error).
  :- instance stream.reader(io.input_stream, line, io, io.error).
  :- instance stream.reader(io.input_stream, text_file, io, io.error).
@@ -1475,7 +1475,7 @@
  :- instance stream.seekable(io.binary_output_stream, io).

  :- instance stream.stream(io.binary_input_stream,  io).
-:- instance stream.input(io.binary_input_stream,  io, io.error).
+:- instance stream.input(io.binary_input_stream, io).
  :- instance stream.reader(io.binary_input_stream, int, io, io.error).
  :- instance stream.putback(io.binary_input_stream, int, io, io.error).
  :- instance stream.seekable(io.binary_input_stream, io).
@@ -9066,7 +9066,7 @@
      pred(name/4) is io.input_stream_name
  ].

-:- instance stream.input(io.input_stream, io, io.error) where [].
+:- instance stream.input(io.input_stream, io) where [].

  :- instance stream.reader(io.input_stream, char, io, io.error)
      where
@@ -9188,7 +9188,7 @@
      pred(name/4) is io.binary_input_stream_name
  ].

-:- instance stream.input(io.binary_input_stream, io, io.error)
+:- instance stream.input(io.binary_input_stream, io)
      where [].

  :- instance stream.reader(io.binary_input_stream, int, io, io.error)
Index: library/stream.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/stream.m,v
retrieving revision 1.6
diff -u -r1.6 stream.m
--- library/stream.m	6 Mar 2007 12:43:34 -0000	1.6
+++ library/stream.m	20 Apr 2007 06:06:55 -0000
@@ -92,16 +92,15 @@

      % An input stream is a source of data.
      %
-:- typeclass stream.input(Stream, State, Error)
-    <= ( stream(Stream, State), stream.error(Error), (Stream -> Error) )
-    where [].
+:- typeclass stream.input(Stream, State) <= stream(Stream, State) where [].

      % A reader stream is a subclass of specific input stream that can be
      % used to read data of a specific type from that input stream.
      % A single input stream can support multiple reader subclasses.
      %
  :- typeclass stream.reader(Stream, Unit, State, Error)
-    <= stream.input(Stream, State, Error) where
+    <= ( stream.input(Stream, State), stream.error(Error),
+        (Stream, Unit -> Error)) where
  [
      % Get the next unit from the given stream.
      % The get operation should block until the next unit is available.
@@ -151,8 +150,8 @@
      % and destination of data, i.e. it is a both an input and
      % an output stream.
      %
-:- typeclass stream.duplex(Stream, State, Error)
-    <= ( stream.input(Stream, State, Error), stream.output(Stream, State))
+:- typeclass stream.duplex(Stream, State)
+    <= ( stream.input(Stream, State), stream.output(Stream, State))
          where [].

  %----------------------------------------------------------------------------%
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list