
13 Sep
2010
13 Sep
'10
7:34 p.m.
On Mon, Sep 13, 2010 at 7:53 PM, Alex Rozenshteyn
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.