
Hi, We have ForeignPtr. Why isn't there a corresponding ForeignFunPtr? Thanks, Maurício

the purpose of ForeignPtr is to attach a finalization procedure to the object behind the pointer. for example, you can have close called aimplicitly whenever the garbage collector finds you don't need a file handle any more. function pointers do not need finalization. cheers, matthias On Sat, Sep 05, 2009 at 07:51:59PM -0300, Maur??cio CA wrote:
To: haskell-cafe@haskell.org From: Maur??cio CA
Date: Sat, 05 Sep 2009 19:51:59 -0300 Subject: [Haskell-cafe] ForeignFunPtr Hi,
We have ForeignPtr. Why isn't there a corresponding ForeignFunPtr?
Thanks, Maurício
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
** ACCEPT: CRM114 PASS osb unique microgroom Matcher ** CLASSIFY succeeds; success probability: 0.9999 pR: 4.1765 Best match to file #0 (nonspam.css) prob: 0.9999 pR: 4.1765 Total features in input file: 2256 #0 (nonspam.css): features: 758386, hits: 2818973, prob: 1.00e+00, pR: 4.18 #1 (spam.css): features: 1686574, hits: 3077879, prob: 6.66e-05, pR: -4.18

Isn't freeHaskellFunPtr a required finalization procedure? Maurício
the purpose of ForeignPtr is to attach a finalization procedure to the object behind the pointer. for example, you can have close called aimplicitly whenever the garbage collector finds you don't need a file handle any more. function pointers do not need finalization.
We have ForeignPtr. Why isn't there a corresponding ForeignFunPtr?

You are right, I forgot about callbacks. freeHaskellFunPtr is only for Haskell functions packaged for usage by the foreign code. Example from the FFI specification, Section 5.4.2: type Compare = Int -> Int -> Bool foreign import ccall "wrapper" mkCompare :: Compare -> IO (FunPtr Compare) If you, say, x = mkCompare (<) and at some point decide x is not needed in your foreign code any more, it has to be freed by hand. This is the only case in which you are allowed to use freeHaskellFunPtr. The (much less interesting) case that I was thinking about, where FunPtr is used for foreign C functions, usually requires no finalization. ForeignPtr is used for foreign objects used by Haskell. The garbage collector (gc) can decide whether the object is still in use and, if it's not, finalize it. A Haskell function wrapped in a FunPtr is used in the foreign world. Haskell gc cannot be made responsible for finalizing it. In fact, (unless the foreign world has some gc of its own) there is no way for any compiler of deciding when to finalize at all. The programmer needs to decide this by calling freeHaskellFunPtr, just like she needs to decide when to free mallocked memory in C. Does that make more sense? Please kick me again if you are still not buying it. :-) cheers, matthias On Sun, Sep 06, 2009 at 02:53:52PM -0300, Maur??cio CA wrote:
To: haskell-cafe@haskell.org From: Maur??cio CA
Date: Sun, 06 Sep 2009 14:53:52 -0300 Subject: [Haskell-cafe] Re: ForeignFunPtr Isn't freeHaskellFunPtr a required finalization procedure?
Maurício
the purpose of ForeignPtr is to attach a finalization procedure to the object behind the pointer. for example, you can have close called aimplicitly whenever the garbage collector finds you don't need a file handle any more. function pointers do not need finalization.
We have ForeignPtr. Why isn't there a corresponding ForeignFunPtr?
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
** ACCEPT: CRM114 PASS osb unique microgroom Matcher ** CLASSIFY succeeds; success probability: 1.0000 pR: 5.6531 Best match to file #0 (nonspam.css) prob: 1.0000 pR: 5.6531 Total features in input file: 2752 #0 (nonspam.css): features: 758386, hits: 2838587, prob: 1.00e+00, pR: 5.65 #1 (spam.css): features: 1686574, hits: 3088399, prob: 2.22e-06, pR: -5.65
participants (2)
-
Maurício CA
-
mf-hcafe-15c311f0c@etc-network.de