On Sat, 18 Oct 2003 19:17:06 -0700 (PDT) Hal Daume III <hdaume@ISI.EDU> wrote:
It is unsafe because, in general, lazy IO is a bad idea. In particular:
foo f x = do h <- openFile x ReadMode t <- hGetContents h v <- f t hClose h return t
will do substantially different things depending on the strictness of 'f'. For instance, if 'f' is 'return . head', you might get a 'head:: empty list' error, while if 'f' is 'evaluate . head', you won't.
I don't understand the details of your example (for instance, what does "evaluate" do? I found a reference to it in the GHC manual under Debug.QuickCheck, but couldn't figure out what it.), but get the general point. In my case, I wanted to represent a directory tree that was too big to fit in memory. I was planning on declaring it as data DirTree = DirTree File [DirTree] but then I apparently need lazy IO. If lazy IO is bad, is data DirTree = DirTree File [IO DirTree] a better way of doing it? P.S. Thanks for your haskell book. I read it and learned a lot. -- Ben Escoto