[Haskell-cafe] IO, sequence, lazyness, takeWhile
Brandon S Allbery KF8NH
allbery at ece.cmu.edu
Sun Dec 19 20:10:12 CET 2010
-----BEGIN PGP SIGNED MESSAGE-----
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 is, it will keep going until the list is
exhausted), but repeat creates an infinite list. You want the stop
condition between the map-report and the repeat-getLine.
- --
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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk0OWJQACgkQIn7hlCsL25Wb2gCgw3GKF/rBdXL2LIsV5qUVSa1M
ZfEAoL5Vzd9+F7+NDqOAP7s2pyxtmJ0S
=bU/D
-----END PGP SIGNATURE-----
More information about the Haskell-Cafe
mailing list