[Haskell-cafe] IORefs and weak pointers

Job Vranish jvranish at gmail.com
Mon Nov 2 14:01:27 EST 2009


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 <patai_gergely at fastmail.fm>

> 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# r v f s of (# s', w #) -> (# s', Weak w #)
>
> This works perfectly when the code is compiled both with and without
> optimisations, but ghci chokes on it with an internal error. So my
> question is if I can expect this to work at least this much in the long
> run, or is it a hopelessly fragile hack?
>
> Gergely
>
> --
> http://www.fastmail.fm - Same, same, but different...
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091102/3dbf50ef/attachment.html


More information about the Haskell-Cafe mailing list