[Haskell-cafe] Is it safe to use unsafePerformIO here?

Cristiano Paris frodo at theshire.org
Fri Sep 18 04:56:08 EDT 2009

On Fri, Sep 18, 2009 at 5:15 AM, Daniel Fischer
<daniel.is.fischer at web.de> wrote:
> ...
> But that does something completely different from what Cristiano wants to do.
> He wants to read many files files quasi-parallel.
> As far as I can tell, he needs to read a small chunk from the beginning of every file,
> then, depending on what he got from that, he needs to read the rest of some files.
> If he reads all the files lazily, he (maybe) runs into the open file limit (a semi-closed
> handle is still open from the OS' point of view, isn't it?).

Not quite. In one case I want to dumbly read all the files' metadata
and printing them out sorted: reading the next file doesn't depend on
what happened previously so they could be read in parallel indeed. In
the other case, it reads a specific file completely and print
everything out. In both cases, I want to use the same code for
reading, exploiting laziness in order not to read the body of files if
only metadata are requested.

> I would separate the reading of headers and bodies, reopening the files whose body is
> needed, for some (maybe compelling) reason he wants to do it differently.

Yes, that's the way Haskell forces you to do that as it's the only way
for you to go safe. But, if you know more about your code, you can use
unsafe(Perform|Interleave)IO to assure the compiler that everything's


More information about the Haskell-Cafe mailing list