[Haskell-cafe] I/O interface (was: Re: Hugs vs GHC)

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Sun Jan 16 09:32:22 EST 2005


John Meacham <john at repetae.net> writes:

> I was thinking of it as a better implementation of a stream interface
> (when available).

I'm not convinced that the stream interface
(http://www.haskell.org/~simonmar/io/System.IO.html) works at all,
i.e. whether it's complete, implementable and convenient.

Convenience. I'm worried that it uses separate types for various
kinds of streams: files, pipes, arrays (private memory), and sockets.
Haskell is statically typed and lacks subsumption. This means that
even though streams are unified by using a class, code which uses
a stream of an unknown kind must be either polymorphic or use
existential quantification.

Completeness. Unless File{Input,Output}Stream uses {read,write}()
rather than file{Read,Write}, openFile provides only a subset of
the functionality of open(): it works only with seekable files,
e.g. not with "/dev/tty".

What is the type of stdin/stdout? They may be devices or pipes
(not seekable), regular files (seekable), sockets...

Note that even when they are regular files, emulating stream I/O
in terms of either pread/pwrite or mmap does not yield the correct
semantics of sharing the file pointer between processes. If we have
a shell script which runs Haskell programs which write to stdout,
it should be possible to redirect the output of the script as a whole.

> Exploiting the advantages of mapped files for stream I/O
>  http://www.cs.toronto.edu/pub/reports/csrg/267/267.ps

The advantage of reducing copying between buffers is lost in Haskell:
file{Read,Write} use a buffer provided by the caller instead of giving
a buffer for the caller to examine or fill.

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


More information about the Haskell-Cafe mailing list