
The reason I ask is that I plan on making a simulation, which will run until
the user decides to pause.
Potentially, I could keep state and update it, but that doesn't seem
haskelly. With an infinite list, I even get history for free.
On Mon, Sep 13, 2010 at 7:34 PM, Felipe Lessa
On Mon, Sep 13, 2010 at 7:53 PM, Alex Rozenshteyn
wrote: Is there a way to take a given monad's bind and wrap it to make it more lazy? It doesn't seem like there should be, but I'm being hopeful.
I wouldn't bother with that. Just write the following and be happy =).
iterateM :: (Monad m) => Int -> (a -> m a) -> a -> m [a] iterateM 0 _ _ = return [] iterateM n act start = do next <- act start rest <- iterateM (n-1) act next return (start : rest)
However, I think the answer of your question is "no". And in cases where you can do something similar (e.g. in IO you can use unsafeInterleaveIO), most of the time it isn't the best solution.
Cheers!
-- Felipe.
-- Alex R