[Haskell-cafe] IO and lazyness.

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Tue Mar 6 16:25:45 EST 2007

On Mar 6, 2007, at 16:22 , D.V. wrote:

> On 3/6/07, mm <schneegloeckchen at gmx.li> wrote:
>> I cannot help you with your question more than pointing you to
>> http://bugs.darcs.net/issue391
>> where Simon Marlow explains how to avoid "IO.bracket".
> I'm using Control.Exception's bracket.
> Also, following Jeremy's advice, I replaced the last line of rechf2
> with   return $! rech r $ lines f       and indeed it works.
> I don't understand why it doesn't without the !
> The documentation for hGetContents says the items are read on demand.
> the function rech needs the strings so they should be read on demand.
> This confuses me :(

Because rech is lazy so it only reads them when something demands it  
do so (e.g. IO, or $! which forces strict evaluation).

brandon s. allbery    [linux,solaris,freebsd,perl]     allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH

More information about the Haskell-Cafe mailing list