You probably just want to hold onto weak references for your 'isStillNeeded' checks. <br><br>Otherwise the isStillNeeded check itself will keep you from garbage collecting!<br><br><a href="http://cvs.haskell.org/Hugs/pages/libraries/base/System-Mem-Weak.html">http://cvs.haskell.org/Hugs/pages/libraries/base/System-Mem-Weak.html</a><br>
<br>-Edward Kmett<br><br><div class="gmail_quote">On Wed, Jan 6, 2010 at 9:39 AM, Miguel Mitrofanov <span dir="ltr"><<a href="mailto:miguelimo38@yandex.ru">miguelimo38@yandex.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I'll take a look at them.<br>
<br>
I want something like this:<br>
<br>
refMaybe b dflt ref = if b then readRef ref else return dflt<br>
refIgnore ref = return "blablabla"<br>
refFst ref =<br>
do<br>
(v, w) <- readRef ref<br>
return v<br>
test =<br>
do<br>
a <- newRef "x"<br>
b <- newRef 1<br>
c <- newRef ('z', Just 0)<br>
performLocalGC -- if necessary<br>
x <- isStillNeeded a<br>
y <- isStillNeeded b<br>
z <- isStillNeeded c<br>
u <- refMaybe y "t" a -- note that it wouldn't actually read "a",<br>
-- but it won't be known until runtime.<br>
w <- refIgnore b<br>
v <- refFst c<br>
return (x, y, z)<br>
<br>
so that "run test" returns (True, False, True).<div><div></div><div class="h5"><br>
<br>
Dan Doel wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Wednesday 06 January 2010 8:52:10 am Miguel Mitrofanov wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Is there any kind of "ST" monad that allows to know if some STRef is no<br>
longer needed?<br>
<br>
The problem is, I want to send some data to an external storage over a<br>
network and get it back later, but I don't want to send unnecessary data.<br>
<br>
I've managed to do something like that with weak pointers,<br>
System.Mem.performGC and unsafePerformIO, but it seems to me that invoking<br>
GC every time is an overkill.<br>
<br>
Oh, and I'm ready to trade the purity of runST for that, if necessary.<br>
</blockquote>
<br>
You may be able to use something like Oleg's Lightweight Monadic Regions to get this effect. I suppose it depends somewhat on what qualifies a reference as "no longer needed".<br>
<br>
<a href="http://www.cs.rutgers.edu/%7Eccshan/capability/region-io.pdf" target="_blank">http://www.cs.rutgers.edu/~ccshan/capability/region-io.pdf</a><br>
<br>
I'm not aware of anything out-of-the-box that does what you want, though.<br>
<br>
-- Dan<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br>
</blockquote>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>