Finalizers: conclusion?

Malcolm Wallace Malcolm.Wallace at
Mon Oct 21 12:50:01 EDT 2002

"Simon Marlow" <simonmar at> writes:

> Ok, I'm sad to say that the problem we recently uncovered to do with
> finalizers sharing values with the rest of the program essentially kills
> off the possibility of doing Haskell finalizers in systems without
> proper concurrency support.

Well, I'm not yet totally convinced that we can't do it, but I'll happily
leave it for another time to work out how.

> Let's keep C finalizers for the FFI spec.  In GHC I imagine we'll
> continue to offer Haskell finalizers as an extension, but I haven't
> decided on an interface yet (suggestions welcome).

Since ghc-5.04.x already has the published interface

  module Foreign.ForeignPtr
    newForeignPtr          :: Ptr a -> IO () -> ForeignPtr a
    addForeignPtrFinalizer :: ForeignPtr a -> IO () -> IO ()

I suggest we keep those names for the "Haskell finaliser" extension.
This would eliminate version configuration questions for both existing
and future code that uses the interface.

I quite liked the suggestion of

    newUnsafeForeignPtr          :: Ptr a -> FunPtr (Ptr a->IO ()) -> ForeignPtr a
    addUnsafeForeignPtrFinalizer :: ForeignPtr a -> FunPtr (Ptr a->IO ()) -> IO ()

for the C-finaliser standard.


More information about the FFI mailing list