Proposed change to ForeignPtr

Alastair Reid alastair at
Tue Sep 3 13:10:47 EDT 2002

[Now that we've gotten the library specification issue out of the way,
I'd like to revive discussion of this topic.  Last time we discussed
it, there seemed to be concensus that we would make a change but I
didn't get much response when I made a concrete proposal.  I'd like to
resolve this promptly so that the impending Hugs release can match
what the spec says (or vice-versa...).]

Since requiring ForeignPtr.newForeignPtr would require preemptive
concurrency (see previous discussion), I propose the following changes:

1) Add these functions:

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

   It is implementation defined whether the free functions are allowed
   to call Haskell functions.

2) Remove newForeignPtr and addForeignPtrFinalizer
   [GHC can go ahead and list them as non-standard extensions]

There's a minor issue about whether the old function names should be
reused (leaving GHC to come up with its own names) or not.  I have
ceased to care either way.

Alastair Reid                 alastair at  
Reid Consulting (UK) Limited

More information about the FFI mailing list