[Haskell-cafe] Storables and Ptrs

Erik Hesselink hesselink at gmail.com
Mon Dec 6 10:01:00 CET 2010


> This can be used to call into C code expecting pointer input or output
> types to great effect:
>
> wrapperAroundForeignCode :: InputType -> IO OutputType
> wrapperAroundForeignCode in =
>  alloca $ \inPtr ->
>  alloca $ outPtr -> do
>    poke inPtr in
>    c_call inPtr outPtr
>    peek outPtr

There is also 'with' (:: Storable a => a -> (Ptr a -> IO b) -> IO b),
which is exactly the combination of 'alloca' and 'poke' you use on
'in'.

Erik



More information about the Haskell-Cafe mailing list