6 Dec
2010
6 Dec
'10
4:01 a.m.
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