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

Galchin, Vasili vigalchin at gmail.com
Mon Jul 28 20:14:47 EDT 2008


> 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)


      ^^^ I am somewhat new to Haskell. Not a total newbie! But what exactly
does the above mean? Are the three references of "AIOCB" in different
namespaces? If it too much trouble to explain, can you point me at Haskell
URL to read?


>
>
> 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).
>
> Duncan
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080728/32b2edb7/attachment.htm


More information about the Haskell-Cafe mailing list