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 ' '))
>          outmsg x = output ('\r':msg++show x) >> hFlush stderr
>          ct s ys = let (a,b) = splitAt (step-1) ys
>                        next  = s+step
>                    in case b of [b1] -> map return a ++ [outmsg (s+step) >> 
> hPutStr stderr post >> return b1]
>                                 []   -> map return (init a) ++ [outmsg 
> (s+length a) >> hPutStr stderr post >> return (last a)]
>                                 _ -> map return a ++ [outmsg s >> return 
> (head b)] ++ ct next (tail b)

It wraps a list with IO operations, so that progress can be reported
while evaluating the list elements.  Unfortunately, there seems to be
a "stricness leak" here - and consequently, it does not work on an
infinite list. 

I'm not sure why this happens, can anybody else see it?

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to