Jeff Polakow [EMAIL PROTECTED] writes:
Besides anything else, sequence will diverge on an infinite list.
Argh, of course. Thanks!
It is necessary to compute all of the computations in the list before
returning
any of the pure resulting list.
Replacing sequence with sequence', given as:
Some time ago, I posted this code:
countIO :: String - String - Int - [a] - IO [a]
countIO msg post step xs = sequence $ map unsafeInterleaveIO ((blank
outmsg (0::Int) c):cs)
where (c:cs) = ct 0 xs
output = hPutStr stderr
blank= output ('\r':take 70 (repeat '
Hello,
countIO :: String - String - Int - [a] - IO [a]
countIO msg post step xs = sequence $ map unsafeInterleaveIO
((blank outmsg (0::Int) c):cs)
where (c:cs) = ct 0 xs
output = hPutStr stderr
blank= output ('\r':take 70 (repeat ' '))
outmsg x
You mean for the IO monad, right?
take 10 $ execWriter $ sequence $ repeat $ tell ([3]::[Int])
/ Emil
On 10/30/2007 02:04 PM, Jeff Polakow wrote:
Hello,
countIO :: String - String - Int - [a] - IO [a]
countIO msg post step xs = sequence $ map unsafeInterleaveIO
((blank outmsg
I forgot to send this reponse to haskell-cafe earlier...
Hello,
You mean for the IO monad, right?
Sorry. I meant divergence is unavoidable for any strict Monad, such as IO.
However, sequence will always compute over the entire list; if the
resulting computation itself is lazy then the