[Haskell-cafe] Is it safe to use unsafePerformIO here?
Cristiano Paris
frodo at theshire.org
Thu Sep 17 16:20:55 EDT 2009
On Thu, Sep 17, 2009 at 10:01 PM, Daniel Fischer
<daniel.is.fischer at web.de> wrote:
> ...
> readBit fn = do
> txt <- readFile fn
> let (l,_:bdy) = span (/= '\n') txt
> return $ Bit (read l) bdy
>
> ?
>
> With
>
> main = do
> args <- getArgs
> let n = case args of
> (a:_) -> read a
> _ -> 1000
> bl <- mapM readBit ["file1.txt","file2.txt"]
> mapM_ (putStrLn . show . index) $ sortBy (comparing index) bl
> mapM_ (putStrLn . take 20 . drop n . body) bl
Yes, it *seems* to work but... the files don't get closed (readFile is
unfinished until body is read) so I think I'm going to have problems
when the number of files to read is higher than the maximum number of
open handles a process can have.
That's a possibility I considered even if not directly using readFile.
Cristiano
More information about the Haskell-Cafe
mailing list