S. Alexander Jacobson wrote:
> [...]
> However, Haskell/Com (built on top of Greencard?) seems to be able
> to propagate garbage collection information from Haskell to C so that
> when a Haskell/COM Object is no longer in use, there is some
> functionality decrements its reference counter automatically.
> 
> How does this work?  and can dima use this mechamism to free queries
> when they are no longer needed? ..allowing database queries outside
> the IOMonad?
> [...]

In GHC there is the ForeignObj data type, see sec. 5.4 of the GHC user
manual: In addition to a pointer outside the Haskell world (an Addr in
GHC-speak) it carries around a function pointer to a finalization
routine. The idea is essentially the same as e.g. Java's finalize()
method: When the garbage collector decides that a ForeignObj is going
to be wiped away, the finalization routine gets a chance to do some
cleanup just before the ForeignObj dies. Although the creation of a
ForeignObj must happen in the IO monad

makeForeignObj :: Addr   -- object to be boxed up as a ForeignObj
               -> Addr   -- finaliser 
               -> IO ForeignObj

the ForeignObj itself can be happily handed around to "normal" functions.

Hugs provides ForeignObj, too, but I haven't used it there yet, but it
seems identical to GHC's ForeignObj. This raises an IMHO important
issue: Something like ForeignObj (and StablePtr, Addr, Posix stuff, to
be continued...) should *really* end up in Haskell's standard libs.
Admittedly, these are all things having very little to do with the
merry world of the lambda calculus, they are of crucial importance if
Haskell should be accepted as a non-toy language.

-- 
Sven Panne                                        Tel.: +49/89/2178-2235
LMU, Institut fuer Informatik                     FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen              Oettingenstr. 67
mailto:[EMAIL PROTECTED]            D-80538 Muenchen
http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne


Reply via email to