[Haskell-cafe] Simple network client

Dan Weston westondan at imageworks.com
Wed Jan 30 17:22:11 EST 2008

Peter Verswyvelen wrote:
> main = do
> 	cs <- getLine
> 	putStrLn ("Hello "++cs)
> looks so much like
> main = do
> 	cs <- readFile "foo"
> 	writeFile "foo" cs
> but in the first one cs is strict, while the second it is lazy... But that's
> not obvious.

Now I'm confused (which happens quite a lot, I'm afraid!)

Prelude> readFile undefined
*** Exception: Prelude.undefined

Prelude> readFile undefined >>= \cs -> putStrLn "Hello"
*** Exception: Prelude.undefined

It seems that readFile is strict in its argument. As for getLine, it has 
no argument to be strict in.

What am I missing?


More information about the Haskell-Cafe mailing list