[Haskell-cafe] operating on a hundred files at once

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Mon Apr 9 18:50:59 EDT 2007


On Mon, 2007-04-09 at 14:40 -0400, Jefferson Heard wrote:
> Thanks for the advice.  I'm not so much interested in performance here,
> as this is just a one-off.  Disk thrashing or not, these files are only
> a few hundred K apiece, and I can't imagine that the whole computation
> will take more than a few minutes.  
> 
> My question is more about how to deal with the IO monad "pollution" of
> all the data in a situation where you have N instances of IO [a] at step
> 1, and you have M computations to perform on those instances, which are
> all monad-free.

Perhaps you want one of these functions:

sequence :: Monad m => [m a] -> m [a]

sequence_ :: Monad m => [m a] -> m ()

for example in the case of IO it's:

sequence :: [IO a] -> IO [a]
sequence_ :: [IO a] -> IO ()

ie it takes a pure list of IO actions and sticks them together into one
IO action, or to put it another way, it performs all the actions in
sequence.


Is this what you meant?

Duncan



More information about the Haskell-Cafe mailing list