How to implement lazy iterate when IO is involved in Haskell
问题 I'm using IO to encapsulate randomness. I am trying to write a method which iterates a next function n times, but the next function produces a result wrapped in IO because of the randomness. Basically, my next function has this signature: next :: IO Frame -> IO Frame and I want to start with an initial Frame , then use the same pattern as iterate to get a list [Frame] with length n . Essentially, I'd like to be able to write the following: runSimulation :: {- parameters -} -> IO [Frame]