Re: [Haskell-cafe] IORefs and weak pointers

2009-11-04 Thread Job Vranish
Wow, this looks like a bug to me. If it's not a bug, then it's horribly unintuitive. I extended your example in an effort to figure out what was going on. Apparently weak pointers loath live IORefs: import Data.IORef import Data.Maybe import System.Mem import System.Mem.Weak import Control.Monad

Re: [Haskell-cafe] IORefs and weak pointers

2009-11-02 Thread Patai Gergely
> Could mkWeakPair do what you want? > http://haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-Weak.html#v:mkWeakPair No, it's just a convenience function that doesn't help much, because the value already refers to the IORef anyway. Here's a minimal example to illustrate the problem: im

Re: [Haskell-cafe] IORefs and weak pointers

2009-11-02 Thread Job Vranish
Could mkWeakPair do what you want? http://haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-Weak.html#v:mkWeakPair Or are you trying to do something else? - Job 2009/11/2 Patai Gergely > Hello all, > > I wanted to create a weak pointer with an IORef as the key and something > else as

Re: [Haskell-cafe] IORefs and weak pointers

2009-11-02 Thread Patai Gergely
> Is the IORef or the value in the IORef your key? I want the IORef itself to be the key. However, that doesn't work with optimisations turned on (the pointers get wiped out at the first gc), I guess because they remove the box around the MutVar#. Extracting that MutVar# seems to solve the problem.

Re: [Haskell-cafe] IORefs and weak pointers

2009-11-02 Thread John Van Enk
Is the IORef or the value in the IORef your key? 2009/11/2 Patai Gergely > Hello all, > > I wanted to create a weak pointer with an IORef as the key and something > else as the value, but I saw no way to do it through the API provided. > After some experimentation I came up with the following ab

[Haskell-cafe] IORefs and weak pointers

2009-11-02 Thread Patai Gergely
Hello all, I wanted to create a weak pointer with an IORef as the key and something else as the value, but I saw no way to do it through the API provided. After some experimentation I came up with the following abomination for a solution: myWeakRef (IORef (STRef r)) v f = IO $ \s -> case mkWeak