
Brian Hulley wrote: [...]
Ref.write proxiesRef $! (weakProxy : proxies)
(This is nothing to do with your main question, but the strict application looks unnecessary there. Its right hand side is already a constructor cell.) [...]
In other words, if the entry for the proxy in the table stored in the Model dies, can I be absolutely 100% sure that this means the proxy no longer exists in any shape or form in the running program?
My reading of the semantics (http://haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-Weak.html#...) is that you can be sure the proxy *object* is gone. As for referential transparency... Fan-in: If you create equivalent proxies in different calls to createProxy, it's possible that they'll end up referring to the same object (e.g. if the compiler or RTS does something fancy, or you use a memoised smart constructor). So then a single live proxy object *could* protect many elements of your Weak Proxy list from scavenging. Fan-out: It would seem perverse to cry "referential transparency!" and spontaneously clone one of your proxy objects. That *could* lead to deRefWeak returning Nothing while an *equivalent* Proxy object is still alive. Might you run your program on an avant-garde distributed RTS? ;-) Regards, Tom

tpledger@ihug.co.nz wrote:
Brian Hulley wrote: [...]
Ref.write proxiesRef $! (weakProxy : proxies)
(This is nothing to do with your main question, but the strict application looks unnecessary there. Its right hand side is already a constructor cell.)
Yes, thanks for pointing this out.
[...]
In other words, if the entry for the proxy in the table stored in the Model dies, can I be absolutely 100% sure that this means the proxy no longer exists in any shape or form in the running program?
My reading of the semantics (http://haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-Weak.html#...) is that you can be sure the proxy *object* is gone.
My problem is that I don't know what to make of the word "object" in the context of Haskell ie when can I be sure that a value is actually being represented as a pointer to a block of memory and not stored in registers or optimized out? Or is the compiler clever enough to preserve the concept of "object" despite such optimizations? I had been designing my Model/Proxy data types with the Java notion of "everything is a pointer to an object" but is this always correct relative to Haskell as a language or is it just a consequence of the current GHC implementation?
As for referential transparency...
Fan-in: If you create equivalent proxies in different calls to createProxy, it's possible that they'll end up referring to the same object (e.g. if the compiler or RTS does something fancy, or you use a memoised smart constructor). So then a single live proxy object *could* protect many elements of your Weak Proxy list from scavenging.
Fan-out: It would seem perverse to cry "referential transparency!" and spontaneously clone one of your proxy objects. That *could* lead to deRefWeak returning Nothing while an *equivalent* Proxy object is still alive. Might you run your program on an avant-garde distributed RTS? ;-)
Someone else might even if I don't! ;-) In the meantime I found a better solution to my original problem without needing to use weak pointers: I now make the proxy pull the changes from the model instead of making the model push them to all registered proxies, so there is no longer any need to have a table of registered proxies hence no need for weak pointers. Thanks, Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com
participants (2)
-
Brian Hulley
-
tpledger@ihug.co.nz