Ross Paterson ross at
Thu Nov 7 07:58:11 EST 2002

Sorry to ask this again, but I didn't understand the answer last time,
and the need to explicitly free StablePtr's, Haskell FunPtr's and close
foreign handles, etc, is surely a serious wart in the FFI spec.

In Sept 2001 Ashley Yakeley asked why ForeignPtr couldn't be generalized,
i.e. an interface like (slightly modified from the original):

data Proxy a            -- abstract; for GHC, = Proxy ForeignObj# 
instance Eq (Proxy a) 

type Finalizer a = FunPtr (a -> IO ())  -- or IO () for Haskell finalizers

newProxy     :: Finalizable a => a -> Finalizer a -> IO (Proxy a) 
addFinalizer :: Finalizable a => Proxy a -> Finalizer a -> IO () 
withProxy    :: Finalizable a => Proxy a -> (a -> IO b) -> IO b 
touchProxy   :: Finalizable a => Proxy a -> IO () 

class Finalizable a     -- things that are boxes around primitive data

More information about the FFI mailing list