[Haskell-beginners] external sort
Keith Sheppard
keithshep at gmail.com
Sat Jul 11 20:40:10 EDT 2009
I'm reworking external sort to meet the needs of my app and I'm
running into some trouble that I was hoping to get some advice on. I'm
asking a lot of questions here so don't feel obligated to answer them
all if you have input on one point:
The code is here: http://tinyurl.com/extsort
1) The sort gives the correct result, but when I tried to sort very
large files (~4 Gb) I got this message:
tssql: /var/folders/Tl/TlS1rTCyFpWU9s-IsNFkdE+++TI/-Tmp-/sort4106.txt:
openBinaryFile: resource exhausted (Too many open files)
I tried to be careful about limiting the number of open file handles
but I must have done something wrong. Do you see where I'm leaking
file handles?
2) I'm guessing there's a smarter way to do unwrapMonads?
3) I'd like to create a function like BS.hGetContents which lazily
reads the ByteString but in addition to closing the file after the
last byte is read I want it to delete the file that I'm reading from.
Like hGetContentsThenDelete. It seems like
http://hackage.haskell.org/package/lazyio but it isn't clear to me how
I would do this
I cant do
> LazyIO.run $ do
> str <- BS.hGetContents file
> removeFile file
> return str
can I? I assume that would close the file too soon
4) Is there any other wacky stuff in my code that I should change?
I told you it was a lot :-) Thanks!
-Keith
--
keithsheppard.name
More information about the Beginners
mailing list