converting things to and from binary

Simon Marlow
Wed, 21 May 2003 17:17:13 +0100

> Here's another reason why I think it's better to make the monad
> used variable (as with my framework but not Malcolm's).  The main
> method I use for encoding binary data needs access to a bit of extra
> information about what it is encoding it for.  This basically
> can't be done within Malcolm's framework except by, er, parking
> the extra stuff in a global variable and then using another global
> lock as otherwise hell will pop when two threads try to use this
> mechanism at once.

Indeed, this strikes a chord with me since we had exactly this problem
in GHC.  Fortunately in GHC we're using our own copy of the Binary
library, so I was able to hack it to include some extra state in the

> This is sufficiently worthwhile to me that I think I shall probably
> implement it, and then see whether anyone else is interested in using
> it.  I don't think you need any extensions apart from FFI and
> multi-parameter type-classes,

Please take a look at the Binary library posted to the libraries list a
while back, it shows how to do this without using the FFI.

> AND some way of writing/reading
> CChars and CStringLen's to Handles, how do I do this please Simon?
> hPutChar/hGetChar/hPutBuf/hGetBuf?

Not sure why you want to do that, but hPutBuf can output CStrings.