[Haskell-beginners] external sort

Felipe Lessa felipe.lessa at gmail.com
Sat Jul 11 22:27:45 EDT 2009


On Sat, Jul 11, 2009 at 08:40:10PM -0400, Keith Sheppard wrote:
> 4) Is there any other wacky stuff in my code that I should change?

I would probably write readBinFiles as

> readBinFiles :: [String] -> IO [BS.ByteString]
> readBinFiles = mapM readB
>   where readB file = openBinaryFile file ReadMode >>= BS.hGetContents

You may also write pointless code ;)

> readBinFiles :: [String] -> IO [BS.ByteString]
> readBinFiles = mapM_ $ flip (>>=) BS.hGetContents . flip openBinaryFile ReadMode

Another way of improving your code is trying to write the
functions in the order that one would read them (that is,
bottom-up or top-down).  In the start you seem to be following a
top-down approach until you reach a referecen to
bufferPartialSortsBy which is on the other side :).

HTH,

--
Felipe.


More information about the Beginners mailing list