You probably just want to hold onto weak references for your &#39;isStillNeeded&#39; 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">&lt;<a href="mailto:miguelimo38@yandex.ru">miguelimo38@yandex.ru</a>&gt;</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&#39;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 &quot;blablabla&quot;<br>
refFst ref =<br>
   do<br>
      (v, w) &lt;- readRef ref<br>
      return v<br>
test =<br>
   do<br>
      a &lt;- newRef &quot;x&quot;<br>
      b &lt;- newRef 1<br>
      c &lt;- newRef (&#39;z&#39;, Just 0)<br>
      performLocalGC -- if necessary<br>
      x &lt;- isStillNeeded a<br>
      y &lt;- isStillNeeded b<br>
      z &lt;- isStillNeeded c<br>
      u &lt;- refMaybe y &quot;t&quot; a -- note that it wouldn&#39;t actually read &quot;a&quot;,<br>
                            -- but it won&#39;t be known until runtime.<br>
      w &lt;- refIgnore b<br>
      v &lt;- refFst c<br>
      return (x, y, z)<br>
<br>
so that &quot;run test&quot; 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 &quot;ST&quot; 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&#39;t want to send unnecessary data.<br>
<br>
I&#39;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&#39;m ready to trade the purity of runST for that, if necessary.<br>
</blockquote>
<br>
You may be able to use something like Oleg&#39;s Lightweight Monadic Regions to get this effect. I suppose it depends somewhat on what qualifies a reference as &quot;no longer needed&quot;.<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&#39;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>