"interact" behaves oddly if used interactively

Olaf Chitil olaf at cs.york.ac.uk
Wed Oct 1 18:42:00 EDT 2003


Robert Ennals wrote:
> It is wrong for all the same reasons that unsafePerformIO is wrong, except
> that it is worse than that because unsafePerformIO has "unsafe" in the title,
> and people are discouraged from using it without due care. By contrast,
> "interact" and "getContents" are presented as being nice friendly functions
> that everyone should use.
> 
> If I had my way, getContents would be called unsafeGetContents and interact
> would be called unsafeInteract. Even better would be for them to both be
> removed from Haskell completely :-))

I agree that getContents can easily cause some complex and unwanted IO
behaviour and that users should be warned about it. interact probably
only makes sense as the only IO action of a program.

However, they are both not unsafe in the sense that they do not change
the `standard' semantics of Haskell. unsafePerformIO even undermines the
type system.

[begin rant]
I'd be far more in favour of removing polymorphic seq and strictness
annotations. Their presence changes the equational semantics of the
language. Their presence makes most theorems for free invalid.
[end rant]

> But then, if I had my way, I would abandon lazy evaluation correctly and fork
> a strict-by-default language derived from Haskell. I have spent sufficient
> time analysing lazy evaluation during my PhD to become convinced that it is
> the wrong evaluation strategy in 90\% of cases, and that in the 10\% of cases
> where it is needed, the program would be much clearer if this was stated
> explicitly in the program text. Haskell is a good language, pureness is good,
> type classes are good, monads are good - but laziness is holding it back.
> 
> [end rant]




-- 
OLAF CHITIL, 
 Dept. of Computer Science, The University of York, York YO10 5DD, UK. 
 URL: http://www.cs.york.ac.uk/~olaf/
 Tel: +44 1904 434756; Fax: +44 1904 432767


More information about the Haskell-Cafe mailing list