Not seeing the problem in your posted code, I'm guessing that you are opening multiple files in a loop, and failing to close them,
fun foo _ 0 = ()
| foo filenm n = let val _ = TextIO.openIn(filenm) in foo filenm (n - 1) end
fun bar _ 0 = ()
| bar filenm n =
let val ins = TextIO.openIn(filenm)
val _ = TextIO.inputLine(ins)
val _ = TextIO.closeIn(ins)
in bar filenm (n - 1) end
In the following transcript, the call to bar works with 1024, as it opens then closes each input stream sequentially, however the subsequent call to foo fails with the error, as it hits the platform defined limit on the number of open file descriptors.
val foo = fn : string -> int -> unit
val bar = fn : string -> int -> unit
- bar "toomanyfiles.sml" 1024;
val it = () : unit
- foo "toomanyfiles.sml" 1024;
uncaught exception Io [Io: openIn failed on "toomanyfiles.sml", Too many open files]
raised at: Basis/Implementation/IO/text-io-fn.sml:783.25-783.71