[Haskell-cafe] Re: I/O interface

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Thu Jan 13 07:05:45 EST 2005

Ketil Malde <ketil+haskell at ii.uib.no> writes:

> It seemed to me, though, that streams are related to channels,

I'm not sure what exactly do you mean by streams (because they are
only being designed), but differences are:

- A stream is either an input stream or an output stream, while a
  single channel supports reading from one end and writing to the
  other end.

- A stream passes around bytes, which are usually grouped in blocks
  for efficiency. A channel is polymorphic wrt. the element type and
  elements are always processed one by one.

- A stream may be backed by an OS file, pipe, socket etc., while
  a channel exists purely in Haskell.

- A channel is never closed. Reading more data than have been put
  blocks until someone puts more data. A stream can reach its end,
  which is a condition a reader can detect. A stream backed by a pipe
  is similar to a channel of bytes in that the reader blocks until
  someone puts more data, but it can be closed too, which causes the
  reader to observe end of file. A writer to a stream can block too
  when the internal buffer in the kernel is full.

- A stream can be inherited by child processes, and it generally
  continues to work by being linked to the same data sink or source as
  before. A channel is inherited as a whole: there is no communication
  between the two versions of the channel in the two processes.

   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/

More information about the Haskell-Cafe mailing list