Ross Paterson ross at
Mon Feb 3 05:47:59 EST 2003

On Mon, Feb 03, 2003 at 09:20:03PM +1100, m v wrote:
> I do not understand the rational of the type of:
> 	newForeignPtr :: Ptr a -> FunPtr (Ptr a -> IO ()) -> IO (ForeignPtr 
> 	a)
> suppose I have a c function
> 	foreign import ccall fooalloc :: Ptr Foo
> and another
> 	foreign import ccall foofree :: Ptr Foo -> IO ()
> now I want to combine fooalloc and foofree to create a Foreign pointer 
> without wrapping foofree again, as in:
> 	 foreign import "wrapper" mkfoofree :: FunPtr (Ptr Foo -> IO ())
> which I think counter productive - why should I import a function only to 
> have to re-export it again !

You don't need to wrap it -- you can import its address with

	foreign import ccall "&foofree" foofreeptr :: FunPtr (Ptr a -> IO ())

> previouse proposals did not require this - or am I missing something ?
> why should the finaliser be a foreign function ?

It's a long story, but it turned out that Haskell side finalizers are hard
to implement correctly in conventional single-threaded implementations.
After a long discussion on this list in October last year, SimonM came up
with a killer example:

For a summary of the discussion, see

However, only Hugs implements this part of the spec at the moment.

More information about the FFI mailing list