Re: [Haskell-cafe] number of references to a variable

2008-11-02 Thread wren ng thornton

Andrew Coppin wrote:

Jan-Willem Maessen wrote:
 Usually the clever thing you want to know is this is the sole 
 reference to the pointed-to object.


Does GHC have weak references? (I seem to recall it does...)



http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-Weak.html


As for the uniqueness of a reference to an object, there are 
alternatives to reference-counting techniques. For example, the language 
Clean[1] builds it into the type system (to replace monads) and they've 
gotten very good performance results from doing so. There are other 
linear logic approaches as well, though porting any of these to Haskell 
would take a fair deal of work to make efficient. Certainly a worthy 
research goal, but probably not what you had in mind :)


[1] http://clean.cs.ru.nl/

--
Live well,
~wren
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] number of references to a variable

2008-11-02 Thread wren ng thornton

Alberto G. Corona wrote:

* Certainly a worthy research goal, but probably not what you had in mind
:)

*Not at all, My interest on that was on to improve RefSerialize. Although
the Clean people has done a superb job on optimization. By the way, I'm not
sure if uniqueness is the cause of his performance. I tested Haskell code
generated using Maybe with and without monad instance and the monad does not
impose any overhead at all.


Oh, I wasn't saying that monads impose any overhead. Rather, the Clean 
folks aren't fans of monads and so they use uniqueness typing in order 
to provide the same kind of solution to IO while retaining functional 
purity. GHC's implementation of IO is actually very similar under the 
hood to what Clean does, though that's not necessarily true of other monads.


Even though they seem to intersect at IO, the ideas of monads and linear 
logics are orthogonal. The big optimization trick with linear logic is, 
since you know when some object is uniquely referenced, you know when 
it's safe to destructively update it in situ. For example, you can 
reverse a spine-unique list in linear time with zero space (modulo 
registers) by just inverting the spine pointers as you traverse it. 
Since it's uniquely referenced, noone else will notice so referential 
transparency is preserved. Doing it this way saves on allocation costs 
and on garbage collection.


There are certainly other ways to use the information that some object 
is held only by a single reference, but Clean's optimizations are the 
first that leap to my mind.


--
Live well,
~wren
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] number of references to a variable

2008-11-01 Thread Alberto G. Corona
Is there a way to know the number of memory references for a variable?. The
runtime must know it but i do not know if this available for the program
trough any low level trick

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


Re: [Haskell-cafe] number of references to a variable

2008-11-01 Thread Andrew Coppin

Alberto G. Corona wrote:
Is there a way to know the number of memory references for a variable?. 
The runtime must know it but i do not know if this available for the 
program trough any low level trick


More precisely, the GC computes it each time it runs. (And only computes 
it precisely during a major pass, not the more frequent minor passes.)


You can attach a finaliser to an object, and that'll allow you to know 
when the reference count reaches zero. But beyond that, I don't know.


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


Re: [Haskell-cafe] number of references to a variable

2008-11-01 Thread Jan-Willem Maessen


On Nov 1, 2008, at 9:38 AM, Andrew Coppin wrote:


Alberto G. Corona wrote:
Is there a way to know the number of memory references for a  
variable?. The runtime must know it but i do not know if this  
available for the program trough any low level trick


More precisely, the GC computes it each time it runs. (And only  
computes it precisely during a major pass, not the more frequent  
minor passes.)


Even this isn't quite true for most GC algorithms.  The GC only needs  
to compute whether there is 0 or = 1 reference to a given location  
(with some special weasel words for stuff with finalizers defined).   
If you can see it, the answer is always =1, so this information is  
much less useful than you might think!


Usually the clever thing you want to know is this is the sole  
reference to the pointed-to object.  If that's what you're interested  
in, try looking up one-bit reference counting, but note that like  
any accurate reference counting technique it's really inefficient in  
practice compared to GC.  [There are efficient reference counting  
techniques, but they defer refcount updates in various subtle ways.   
Also, every ref count technique requires a cycle detector.]


-Jan-Willem Maessen

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


Re: [Haskell-cafe] number of references to a variable

2008-11-01 Thread Andrew Coppin

Jan-Willem Maessen wrote:


On Nov 1, 2008, at 9:38 AM, Andrew Coppin wrote:


Alberto G. Corona wrote:
Is there a way to know the number of memory references for a 
variable?. The runtime must know it but i do not know if this 
available for the program trough any low level trick


More precisely, the GC computes it each time it runs. (And only 
computes it precisely during a major pass, not the more frequent 
minor passes.)


Even this isn't quite true for most GC algorithms.  The GC only needs 
to compute whether there is 0 or = 1 reference to a given location.  
If you can see it, the answer is always =1, so this information is 
much less useful than you might think!


Quite right.

Usually the clever thing you want to know is this is the sole 
reference to the pointed-to object.


Does GHC have weak references? (I seem to recall it does...)

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