System.Mem.Weak breaks referential transparency
|Reported by:||drtomc@…||Owned by:|
|Type of failure:||Test Case:|
|Related Tickets:||Differential Revisions:|
Consider the following two functions:
foo = do
mkWeakPtr y (Just launchMissiles)
y = 42
bar = do
mkWeakPtr 42 (Just launchMissiles)
These two functions are equivalent right? After all referential transparency means that if y = 42, then anywhere y occurrs I can write 42. The problem is that if I call foo, and hang on to the return value, then launchMissiles won't be called until some time after I stop using the return value, but if I call bar, then launchMissiles may be called any time, including before bar returns!
Looks to me like finalizers break referential transparency, so System.Mem.Weak is broken, though I'm quite willing to be proven wrong.