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

2010-12-19 Thread Brandon S Allbery KF8NH
-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

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

2010-12-19 Thread Jacek Generowicz
On 2010 Dec 19, at 20:10, Brandon S Allbery KF8NH wrote: -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

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

2010-12-19 Thread Daniel Fischer
On Sunday 19 December 2010 22:18:59, Jacek Generowicz wrote: 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

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

2010-12-19 Thread Carl Howells
Sequence isn't necessarily strict. Sequence, rather necessarily, depends on the semantics of (=) in that monad. Prelude Control.Monad.Identity runIdentity $ take 10 `liftM` sequence (map return $ repeat 5) [5,5,5,5,5,5,5,5,5,5] What matters is if (=) is strict in its first argument. The

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

2010-12-13 Thread Jacek Generowicz
-- Is it possible to rewrite code written in this style untilQuit = do text - getLine report text if text == quit then return () else untilQuit -- in a style using higher order functions for abstract iteration? For -- example, something along these lines: untilQuit' = (fmap

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

2010-12-13 Thread Luke Palmer
On Mon, Dec 13, 2010 at 7:15 AM, Jacek Generowicz jacek.generow...@cern.ch wrote: -- Is it possible to rewrite code written in this style untilQuit = do  text - getLine  report text  if text == quit     then return ()     else untilQuit -- in a style using higher order functions for

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

2010-12-13 Thread Gregory Crosswhite
Take a look at the monad-loops package. Cheers, Greg On 12/13/2010 06:15 AM, Jacek Generowicz wrote: -- Is it possible to rewrite code written in this style untilQuit = do text - getLine report text if text == quit then return () else untilQuit -- in a style using higher