"interact" behaves oddly if used interactively

John Meacham john at repetae.net
Thu Oct 2 15:19:49 EDT 2003

On Thu, Oct 02, 2003 at 11:48:29AM +0100, Simon Marlow wrote:
> So... you agree that getContents in its current form should really be
> called unsafeGetContents?  Unless perhaps we redefine its semantics to
> either (a) yield a random string or (b) eagerly slurp the entire stream
> contents?

personally, I think the easiest solution would be to punt the whole
issue by having:

lazily read the file if it is mmapable or a pipe

eagerly slurp the whole file if it refers to a tty

this will at least make it much harder for the lazyness of IO to bite an
interactive user. reading from a tty has a real side effect from the
users point of view, so should be done strictly, while in the case of a
presumably immutable (over the course of the program) file it is simply
a (useful) harmless optimization to have the file read lazily.

of course this makes 'interact' not really interactive, but at least the
semantics are clear when typing stuff at it, nothing happens until you
finish. if people want line-by-line interactivity, don't rely on the
evaluation strategy of a particular compiler, use Readline and monads.

John Meacham - California Institute of Technology, Alum. - john at foo.net

More information about the Haskell-Cafe mailing list