[Haskell-cafe] carry "state" around ....

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Sun Jul 20 07:51:21 EDT 2008

On Sat, 2008-07-19 at 23:55 -0500, Galchin, Vasili wrote:
> yes Duncan I am trying to pass-by-value. I am familiar with
> ForeignPtr; however, I don't comprehend what you and Brandon are
> suggesting to do. Could either of you provide a code illustration or
> point at existing code to illustrate your approach?

Take a look at John Meacham's RSA example.

So at the moment you're using using Storable and a Haskell record, say:

data AIOCB = AIOCB { 

and we're suggesting instead:

newtype AIOCB = AIOCB (ForeignPtr AIOCB)

then to access a member use hsc2hs:

getBlah :: AIOCB -> IO Blah
getBlah (AIOCB fptr) =
  withForeignPtr fptr $ \ptr -> {# peek aiocb,blah #} ptr

So you only access the parts you need and keep the aiocb C struct
allocated on the heap (use mallocForeignPtr).


More information about the Haskell-Cafe mailing list