[Haskell-cafe] IO, sequence, lazyness, takeWhile

Jacek Generowicz jacek.generowicz at cern.ch
Sun Dec 19 22:18:59 CET 2010

On 2010 Dec 19, at 20:10, Brandon S Allbery KF8NH wrote:

> Hash: SHA1
> On 12/13/10 09:15 , Jacek Generowicz wrote:
>> untilQuit' = (fmap (takeWhile (/= "quit"))) (sequence $ map (>>=  
>> report)
>> (repeat getLine))
>> -- The latter version shows the report, but it doesn't stop at the
>> -- appropriate place, so I'm guessing that I'm being bitten by my
>> -- ignorance about the interaction of actions and lazyness.
> The reason this doesn't stop where you expect it to is that sequence  
> is
> effectively strict

That would explain it. Thank you.

Where is this fact documented? I mostly rely on Hoogle, which gets me to


which says nothing about strictness.

How could I have known this without having to bother anyone else?

> You want the stop condition between the map-report and the repeat- 
> getLine.

Or, more generally speaking, between sequence, and whatever generates  
the infinite list. But can this be done in a similar style? Could I  
still use takeWhile and somehow lift it into IO?

More information about the Haskell-Cafe mailing list