binary files in haskell
I was wondering if anyone here has a solution for writing binary files that works in hugs and ghc that doesn't require getting libs. I looked at this page: http://haskell.cs.yale.edu/ghc/docs/latest/set/sec-ioexts.html and the haskell.org libraries page and I didn't see anything. the ghc documentation didn't provide any examples so I was unable to figure out how to write a binary file.
[ OK, let's see if I get a typo-free mail out of the door *this* time... :-] Timmy Douglas wrote:
I was wondering if anyone here has a solution for writing binary files that works in hugs and ghc that doesn't require getting libs.
I dont' know exactly about the current status of Hugs' libs, but I fear the answer to your question is "no".
I looked at this page: http://haskell.cs.yale.edu/ghc/docs/latest/set/sec-ioexts.html
... and that was exactly the right place, see section "Bulk transfers" hGetBuf :: Handle -> Addr -> Int -> IO Int hGetBufFull :: Handle -> Addr -> Int -> IO Int hPutBuf :: Handle -> Addr -> Int -> IO Int hPutBufFull :: Handle -> Addr -> Int -> IO ()
and the haskell.org libraries page and I didn't see anything. the ghc documentation didn't provide any examples so I was unable to figure out how to write a binary file.
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
-- Sven Panne Tel.: +49/89/2178-2235 LMU, Institut fuer Informatik FAX : +49/89/2178-2211 LFE Programmier- und Modellierungssprachen Oettingenstr. 67 mailto:sven.panne@informatik.uni-muenchen.de D-80538 Muenchen http://www.informatik.uni-muenchen.de/~Sven.Panne
[ Seems I *can't* mail in a sane way anymore, so please excuse my last half-baked one. But at least I've learned now that Ctrl-RET means "send immediately" in Netscape. Great idea! Here my next try... ] Timmy Douglas wrote:
I was wondering if anyone here has a solution for writing binary files that works in hugs and ghc that doesn't require getting libs.
I dont' know exactly about the current status of Hugs' libs, but I fear the answer to your question is "no".
I looked at this page: http://haskell.cs.yale.edu/ghc/docs/latest/set/sec-ioexts.html [...]
... and that was exactly the right place, see section "Bulk transfers": (http://haskell.cs.yale.edu/ghc/docs/latest/set/sec-ioexts.html#SEC-BULK-TRAN...) hGetBuf :: Handle -> Addr -> Int -> IO Int hGetBufFull :: Handle -> Addr -> Int -> IO Int hPutBuf :: Handle -> Addr -> Int -> IO Int hPutBufFull :: Handle -> Addr -> Int -> IO () These action read/write a given amount of bytes to/from a buffer. There hasn't been much consensus about a higher level interface yet, but you can have a look at my variant sitting on top of this: http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/hslibs/OpenGL/GL/GL_Binary... Not the nicest and most efficient code on earth, but it should be enough to get the idea. Note that in more recent (CVS) versions of GHC, `Addr' (which is deprecated now) has been replaced by `Ptr a'. Any ideas & suggestions for a good binary I/O interface are highly welcome! Cheers, Sven "The Typo" P.
Sven Panne <Sven.Panne@informatik.uni-muenchen.de> said:
[ Seems I *can't* mail in a sane way anymore, so please excuse my last half-baked one. But at least I've learned now that Ctrl-RET means "send immediately" in Netscape. Great idea! Here my next try... ]
Timmy Douglas wrote:
I was wondering if anyone here has a solution for writing binary files that works in hugs and ghc that doesn't require getting libs.
I dont' know exactly about the current status of Hugs' libs, but I fear the answer to your question is "no".
I looked at this page: http://haskell.cs.yale.edu/ghc/docs/latest/set/sec-ioexts.html [...]
... and that was exactly the right place, see section "Bulk transfers": (http://haskell.cs.yale.edu/ghc/docs/latest/set/sec-ioexts.html#SEC-BULK-TRAN...)
hGetBuf :: Handle -> Addr -> Int -> IO Int hGetBufFull :: Handle -> Addr -> Int -> IO Int
hPutBuf :: Handle -> Addr -> Int -> IO Int hPutBufFull :: Handle -> Addr -> Int -> IO ()
These action read/write a given amount of bytes to/from a buffer. There hasn't been much consensus about a higher level interface yet, but you can have a look at my variant sitting on top of this:
I saw this part but I couldn't figure out how I was supposed to open a file and use these functions. So maybe I was looking for an example. I want to try to write a compiler for some language in haskell, but I don't know how to write binary files... It looks like I use openFileEx but I can't get anything to compile without seeing an example of it. Thanks for the reply.
There is actually NO way with haskell 98 to portably read and write binary files. and many libraries which provide this feature are inherently non portable, (they assume a Haskell Char = C char = byte) which is not necisarily the case. I wrote up a proposal for a binary file IO mechanism to be added as a 'blessed addendum' to the standard at best and as a commonly implmented extension (in hslibs) at least.. my original proposal messages to the list can be gotten from http://www.ugcs.caltech.edu/~john/computer/haskell/ although without the messages from others in the list they may seem out of context. -- -------------------------------------------------------------- John Meacham http://www.ugcs.caltech.edu/~john/ California Institute of Technology, Alum. john@foo.net --------------------------------------------------------------
participants (3)
-
John Meacham -
Sven Panne -
Timmy Douglas