On 6 Jan 2010, at 23:21, Edward Kmett wrote:

You probably just want to hold onto weak references for your 'isStillNeeded' checks.

That's what I do now. But I want to minimize the network traffic, so I want referenced values to be garbage collected as soon as possible - and I couldn't find anything except System.Mem.performIO to do the job - which is a bit too global for me.

Otherwise the isStillNeeded check itself will keep you from garbage collecting!

Not necessary. What I'm imagining is that there is essentially only one way to access the value stored in the reference - with readRef. So, if there isn't any chance that readRef would be called, the value can be garbage collected; "isStillNeeded" function only needs the reference, not the value.

Well, yeah, that's kinda like weak references.


http://cvs.haskell.org/Hugs/pages/libraries/base/System-Mem-Weak.html

-Edward Kmett

On Wed, Jan 6, 2010 at 9:39 AM, Miguel Mitrofanov <miguelim...@yandex.ru > wrote:
I'll take a look at them.

I want something like this:

refMaybe b dflt ref = if b then readRef ref else return dflt
refIgnore ref = return "blablabla"
refFst ref =
  do
     (v, w) <- readRef ref
     return v
test =
  do
     a <- newRef "x"
     b <- newRef 1
     c <- newRef ('z', Just 0)
     performLocalGC -- if necessary
     x <- isStillNeeded a
     y <- isStillNeeded b
     z <- isStillNeeded c
     u <- refMaybe y "t" a -- note that it wouldn't actually read "a",
                           -- but it won't be known until runtime.
     w <- refIgnore b
     v <- refFst c
     return (x, y, z)

so that "run test" returns (True, False, True).


Dan Doel wrote:
On Wednesday 06 January 2010 8:52:10 am Miguel Mitrofanov wrote:
Is there any kind of "ST" monad that allows to know if some STRef is no
 longer needed?

The problem is, I want to send some data to an external storage over a
network and get it back later, but I don't want to send unnecessary data.

I've managed to do something like that with weak pointers,
System.Mem.performGC and unsafePerformIO, but it seems to me that invoking
 GC every time is an overkill.

Oh, and I'm ready to trade the purity of runST for that, if necessary.

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".

 http://www.cs.rutgers.edu/~ccshan/capability/region-io.pdf

I'm not aware of anything out-of-the-box that does what you want, though.

-- Dan
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to