Type of newForeignPtr & addForeignPtrFinalizer

Alastair Reid alastair@reid-consulting-uk.ltd.uk
23 Jul 2002 17:42:59 +0100

[This question might be more appropriate for the ffi mailing list]

> I wonder if I might indulge myself with
> another stupid question related to this, that is, why make the
> distinction between Ptr and ForeignPtr at all? [...]

The reason for using ForeignPtr is to attach free functions.

If we were to make Ptr and ForeignPtr the same type, there's be no
way to catch cases where we forget to attach a free function to a Ptr
being returned from C.  The type distinction (and the fact that 
ForeignPtr's must be cast to/from Ptrs when they are passed to C)
acts as a strong reminder to do the right thing.