-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
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
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
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
-- 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
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
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