John Meacham john at
Thu Nov 7 15:37:18 EST 2002

this already exists in GHC, a side effect of Weak pointers is that they
allow finalizers to be assosiated with any value.

addFinalizer :: key -> IO () -> IO () 

A specialised version of mkWeakPtr, where the Weak object returned is
simply thrown away (however the finalizer will be remembered by the
garbage collector, and will still be run when the key becomes

although I would love to see Weak pointers make it into some spec or
another perhaps the FFI is not the right place. (but i wont argue if
people want to add them). 

On Thu, Nov 07, 2002 at 04:53:04PM +0000, Alastair Reid wrote:
> >> On first glance, this looks cool.  What instances do you envision
> >> (assuming I persuaded you that StablePtr and FunPtr should not be)?
> > How about Int (for file descriptors, etc)?
> Ah, got you.
> How about making ForeignPtr slightly more polymorphic so that instead of
> working only on 'Ptr a' it works on 'a'.
> e.g., We'd have:
>   newForeignPtr :: a -> Finalizer a -> IO ForeignThing a
> obviously, we'd want to remove the word 'Ptr' from the name of the type.
> Candidates:
>   ForeignProxy, ForeignObj, Foreign
> I think 'Foreign' is an essential part (at least, given the
> restriction to C finalizers) and I favour the first two over the last
> which seems too general.
> Trivial to implement, might require an additional layer of boxing in
> GHC (maybe in Hugs too - I forget the implementation).
> --
> Alastair
> _______________________________________________
> FFI mailing list
> FFI at

John Meacham - California Institute of Technology, Alum. - john at

More information about the FFI mailing list