ForeignPtr

John Meacham john at repetae.net
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.

http://haskell.org/ghc/docs/latest/html/base/System.Mem.Weak.html

===
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
unreachable).  
===

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). 
	John

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 haskell.org
> http://www.haskell.org/mailman/listinfo/ffi

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



More information about the FFI mailing list