Stability | experimental |
---|---|
Maintainer | Luke Palmer <lrpalmer@gmail.com> |
Data.QuotientRef
Description
A Quotient Reference is a reference cell that needs two values to
dereference. In a way it is a two-dimensional table indexed by references.
The trick is that if a cell is indexed by a
and b
, then if either
a
or b
gets cleaned up by the garbage collector, then so does the
cell, because it would not be able to be accessed anymore.
There are two different types of indices, LeftRef and RightRef. You need one of each, of the same type, to access a cell.
The name comes from the idea that the product of two indices is a reference, so each index is a quotient.
Example usage:
do l_1 <- newLeft l_2 <- newLeft r_1 <- newRight r_2 <- newRight write l_1 r_1 "Foo" write l_2 r_1 "Bar" print =<< read l_1 r_1 -- Just "Foo" print =<< read l_1 r_2 -- Nothing print =<< read l_2 r_1 -- Just "Bar" print =<< read l_2 r_2 -- Nothing
Documentation
The left half of a reference cell. Combine this with a RightRef to access a cell.
The right half of a reference cell. Combine this with a LeftRef to access a cell.