binary files in haskell

Timmy Douglas [email protected]
Sat, 27 Jan 2001 12:11:48 -0600


Sven Panne <[email protected]> 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-TRANSFERS)
>
>   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.