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
Hmm, interesting. This allows the implementation to divorce the object you're interested in finalizing from the object which the finalizer actually watches. eg. data ForeignThing a = ForeignThing a X where X is some object with "identity", i.e. an object which is only explicitly allocated in the IO monad. Examples are IORef, MVar, ForeignPtr - it doesn't really matter, as long as you can attach a finalizer to it and it can't be arbitrary duplicated by the compiler. In GHC, this means we could get rid of the ForeignObj# primitive type. If you want finalizer ordering, as discussed previously, the implementation would have to be data ForeignThing a = ForeignThing a !(IORef [Finalizer a]) (the IORef has identity, so that serves as our X).
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.
Maybe "Finalized"? Cheers, Simon
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.
Maybe "Finalized"?
But then people will start asking why finalizers have to be C functions... (0.5 :-)) I'd say that Finalized would be a fine name for a GHC-specific variant that allows Haskell finalizers. Nice clean design, no particular ffi dependency. Might cover a useful common case that WeakPtrs perhaps don't (???). -- Alastair
participants (2)
-
Alastair Reid -
Simon Marlow