Applicative functor for building C structs with Storable

Adam Langley agl at
Sat Oct 13 13:34:31 EDT 2007

On 10/13/07, Henning Thielemann <lemming at> wrote:
> Are there analogons to ByteString's Put and Get Monads to construct and
> disect binary data in a C struct for exchange with a C program?

The memory layout of structs depends on the ABI of system. You can
take a guess and write code in the Get and Put monads. Your guess will
probably work pretty well within a single architecture (e.g. x86 or

However, the portable way to do this is to get the information from
the C compiler, which is the approach that c2hs[1] and friends use. I
would recommend this unless there's some good reason to think
otherwise. (see [2] for the exact hook)



Adam Langley                                      agl at                       650-283-9641

More information about the Libraries mailing list