
Greetings, I am considering writing -in Haskell of course - a small program to translate binary files to human readable text. The trouble is that I can find no easily digestible tutorial style info on how to do binary IO in Haskell. I have read about some of the libraries that people have created to do binary IO, but the documentation wasn't sufficient to get me started (perhaps because I'm a bit dense, and also relatively new to Haskell). What I would like is to see a short example showing some code that reads from a binary file. I would also like to know what the most widely used library for doing binary IO in Haskell is. I would greatly appreciate it if someone could post a small example or two illustrating how to do binary IO in Haskell using the most widely used binary IO lib (if there is such a thing). Failing that, I would appreciate a link to some Haskell code that does binary IO that I could study. Lastly, if there is a good tutorial on doing binary IO in Haskell then I would appreciate a link to that as well. Thanks in advance, Jeff Lasslett

m4d.skills:
Greetings, I am considering writing -in Haskell of course - a small program to translate binary files to human readable text. The trouble is that I can find no easily digestible tutorial style info on how to do binary IO in Haskell. I have read about some of the libraries that people have created to do binary IO, but the documentation wasn't sufficient to get me started (perhaps because I'm a bit dense, and also relatively new to Haskell). What I would like is to see a short example showing some code that reads from a binary file. I would also like to know what the most widely used library for doing binary IO in Haskell is. I would greatly appreciate it if someone could post a small example or two illustrating how to do binary IO in Haskell using the most widely used binary IO lib (if there is such a thing). Failing that, I would appreciate a link to some Haskell code that does binary IO that I could study. Lastly, if there is a good tutorial on doing binary IO in Haskell then I would appreciate a link to that as well. Thanks in advance, Jeff Lasslett
Here's a howto: http://www.haskell.org/hawiki/BinaryIo Look for the instance Binary code. That's where you set up your binary parsers for each Haskell type. lso, these day,s you can do a fair bit of binary hacking with Data.ByteString, without the Binary class layer over the top. Hope that helps. -- Don

Hello jeff, Saturday, June 24, 2006, 10:19:17 AM, you wrote:
I would greatly appreciate it if someone could post a small example or two illustrating how to do binary IO in Haskell using the most widely used binary IO lib (if there is such a thing). Failing that, I would appreciate a link to some Haskell code that does binary IO that I could study.
the most widely used is NewBinary lib. but nevertheless i suggest you to use my own Streams library. it's close enough to NewBinary in overall ideology, but simpler, easy to install and may become new standard in this area because it has innumerous number of features Download: http://www.haskell.org/library/Streams.tar.gz Installation: run "make install" with my lib, binary I/O can be performed using Handles. there are just a number of new I/O operations what reads and writes words of specified size: main = do h <- openBinaryFile "test" ReadMode i <- getWord32le h j <- getWord8 h .... hout <- openBinaryFile "test" WriteMode putWord32le hout (1::Int) putWord8 hout (2::Int) ... you can use all the Handle operations (hSeek, hFilesize and so on) and even mix binary and text I/O. there are also features to define operations that read and write whole data structures library docs are still unfinished. i will send existing bits of documentation to you via email. i plan to publish final docs at http://haskell.org/haskellwiki/Library/AltBinary but at this moment this page contains only feature list -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (3)
-
Bulat Ziganshin
-
dons@cse.unsw.edu.au
-
jeff lasslett