[Haskell-cafe] Exception: Too many open files

Tomasz Zielonka tomasz.zielonka at gmail.com
Mon Oct 23 15:50:24 EDT 2006


On Mon, Oct 23, 2006 at 08:48:24PM +0200, Bas van Dijk wrote:
> So it seems that 'parseFiles' tries to open all the ~18.000 files and gets 
> exhausted when opening the 14994 file.
> 
> What I would like is 'take 3 =<< parseFiles' to read only the first 3 files.
> 
> Is this possible, and if so, what is the best way to do this?

> parseFiles :: IO [T]
> parseFiles = mapM parseFile =<< getFileFPs

use this function instead of mapM above:

    unsafeInterleaveMapIO f (x:xs) = unsafeInterleaveIO $ do
        y <- f x
        ys <- unsafeInterleaveMapIO f xs
        return (y : ys)
    unsafeInterleaveMapIO _ [] = return []

Best regards
Tomasz


More information about the Haskell-Cafe mailing list