"interact" behaves oddly if used interactively
Dean Herington
heringto at cs.unc.edu
Wed Oct 1 12:16:43 EDT 2003
On Wed, 1 Oct 2003, Keith Wansbrough wrote:
> > 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!
>
> Yes, of course.
>
> Your code above only forces the evaluation of the first cons-cell of
> the list, which is not enough. You want to force the entire list.
> Try
>
> deepSeq :: [a] -> b -> b
> deepSeq (x:xs) y = deepSeq xs y
> deepSeq [] y = y
>
> noninteract f = do
> s <- getContents
> putStr (f (deepSeq s s))
Here's another way to write the above:
import DeepSeq
noninteract f = getContents >>= (putStr . f $!!)
-- Dean
More information about the Haskell
mailing list