Re: how to do lazy IO like getContents?

2003-10-18 Thread Hal Daume III
> 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

Re: how to do lazy IO like getContents?

2003-10-18 Thread Ben Escoto
On Sat, 18 Oct 2003 19:17:06 -0700 (PDT) Hal Daume III <[EMAIL PROTECTED]> 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 diffe

Re: how to do lazy IO like getContents?

2003-10-18 Thread Hal Daume III
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 ge

Re: how to do lazy IO like getContents?

2003-10-18 Thread Ben Escoto
On Sun, 19 Oct 2003 02:03:58 +0200 Nick Name <[EMAIL PROTECTED]> wrote: > You have to use unsafeInterleaveIO, wich lazily defers the IO action > passed as an argument. Look for this function in your documentation, > both hugs and ghc have it. Got it, thanks. Do you know in what sense it is "uns

Re: how to do lazy IO like getContents?

2003-10-18 Thread Nick Name
Alle 01:50, domenica 19 ottobre 2003, Ben Escoto ha scritto: > which only reads one character.  So how do you write getContents in > haskell?  Thanks for any insight. You have to use unsafeInterleaveIO, wich lazily defers the IO action passed as an argument. Look for this function in your documen

how to do lazy IO like getContents?

2003-10-18 Thread Ben Escoto
Hi, I'm trying to do IO and it isn't lazy enough. My problem seems similar to this one: Write a function that lazily reads characters from stdin, just like getContents does. These two don't work: lazyRead :: IO String lazyRead = do first_char <- getChar rest <- lazyRea