"interact" behaves oddly if used interactively
maeder at tzi.de
Wed Oct 1 17:42:51 EDT 2003
>>But looking at the two actions of interact:
>>interact f = do
>> s <- getContents
>> putStr (f s)
>>I would expect the first action to be finished before the second
Keith Wansbrough wrote:
Because the actions are written down in that order? Why not? Why should
I expect pipelining? Occam's razor demands the simplest theory.
> For the use of laziness, consider
> let fib = 0 : 1 : zipWith (+) fib (tail fib) in fib
> and think what would happen if "let" was strict. Programming in
> Haskell can be much more convenient than in strict languages, and
> laziness is assumed in lots of little ways throughout idiomatic Haskell
> code (I'm thinking of the liberal use of "where" and "let" bindings,
> for example).
I know and appreciate these uses of laziness. There are plenty of
examples where eager or lazy evaluation can bite you or save you. It's
good to have both, and even better if you do not need to worry about it
> getContents behaves according to the specification in the standard,
> which is good enough for me. So does putStr.
Allow me to have another opinion, if the consequence is interleaved in-
and output (when I don't want it).
Can actually someone supply an implementation of something like interact
that does no pipelining for the argument "id"? Simply doing "putStr !$ f
!$ s" was not enough!
More information about the Haskell