[Haskell-cafe] Get out structured data from a C/C++ library inHaskell

Donn Cave donn at avvanta.com
Fri Aug 8 21:48:12 UTC 2014


Nicola Gigante <nicola.gigante at gmail.com>,
> Il giorno 08/ago/2014, alle ore 17:29, Donn Cave <donn at avvanta.com> ha scritto:
>> Foreign.Storable is the key to packing and unpacking a struct.  The
>> hsc2hs utility adds some support for struct member names, which will
>> make your code more convenient and robust.  You will also find "peek"
>> and "poke" functions in Foreign.Storable, for pointer access.

...
> Moreover, I see that peek and poke return IO a, so I 
> can't pretend that the interface that I'm wrapping is pure,
> can I?

Funny you should ask ... I just happened to notice something about
pretending an external function is pure, in the library documentation
for Foreign.Marshall.unsafeLocalState.  I can't say for sure whether
it would serve your purpose here or not - the documentation could be
read to say it does, anyway, and the function signature is IO a -> a.

I meant to say, about hsc2hs, documentation can be found in the
GHC user manual, chapter 12 or thereabouts.

	Donn


More information about the Haskell-Cafe mailing list