how to do lazy IO like getContents?

Hal Daume III hdaume at ISI.EDU
Sat Oct 18 22:44:53 EDT 2003

> 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.

evaluate is from Control.Exception; basically it's:

evaluate :: a -> IO a
evaluate x = x `seq` return x

if I recall correctly -- it just forces something to be evaluated.

> 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?

Hard to say.  In this case, lazy io doesn't seem to bad, to me at
least.  but keep in mind that the DirTree can still grow very large if a
lot of it is evaluated.

 - Hal

More information about the Haskell mailing list