[Haskell-beginners] FFI foreignPtr construction
PICCA Frederic-Emmanuel
frederic-emmanuel.picca at synchrotron-soleil.fr
Wed Jan 27 20:49:22 UTC 2016
Thanks for your help
I end up with this code which I find quite elegant :)
-- data Geometry
data HklGeometry
newtype Geometry = Geometry (ForeignPtr HklGeometry) deriving (Show)
newGeometry :: Factory -> IO Geometry
newGeometry f =
Geometry <$> (c_hkl_factory_create_new_geometry f >>= newForeignPtr c_hkl_geometry_free)
foreign import ccall unsafe "hkl.h hkl_factory_create_new_geometry"
c_hkl_factory_create_new_geometry :: Factory -> IO (Ptr HklGeometry)
foreign import ccall unsafe "hkl.h &hkl_geometry_free"
c_hkl_geometry_free :: FunPtr (Ptr HklGeometry -> IO ())
Cheers
Frederic
More information about the Beginners
mailing list