[Haskell-cafe] Exception: Too many open files
bulat.ziganshin at gmail.com
Tue Oct 24 03:01:01 EDT 2006
Tuesday, October 24, 2006, 1:03:55 AM, you wrote:
> Great it works! I didn't know about unsafeInterleaveIO .
> Why is it called 'unsafe'?
> And how does the laziness work? Is it because of the 'let r = ... in (s, r)'?
read either http://haskell.org/haskellwiki/IO_inside
or Simon's paper "awkward squad" mentioned there
in your original program, parseFile don't parsed file. it just
returned thunk (computation) that will parse file when data from this
thunk will be requested. so, your mapM returned 18k of such thunks,
each with its own file open. Tomasz's solution postpone not only
parsing, but the whole parseFile call (including file open) until the
data from this parsing will be really requested. because your next code
uses results of each parsing before using results of next one, this
allows garbage collector to close files of already used parsings
before you go to consume next one. smart solution
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe