|Maintainer||Iavor S. Diatchki <firstname.lastname@example.org>|
The technique for generating new values is based on the paper ''On Generating Unique Names'' by Lennart Augustsson, Mikael Rittri, and Dan Synek.
- data Supply a
- newSupply :: a -> (a -> a) -> IO (Supply a)
- newEnumSupply :: Enum a => IO (Supply a)
- newNumSupply :: Num a => IO (Supply a)
- newDupableSupply :: a -> (a -> a) -> IO (Supply a)
- newDupableEnumSupply :: Enum a => IO (Supply a)
- newDupableNumSupply :: Num a => IO (Supply a)
- supplyValue :: Supply a -> a
- modifySupply :: Supply a -> (Supply a -> b) -> Supply b
- split :: Supply a -> [Supply a]
- split2 :: Supply a -> (Supply a, Supply a)
- split3 :: Supply a -> (Supply a, Supply a, Supply a)
- split4 :: Supply a -> (Supply a, Supply a, Supply a, Supply a)
Creates a new supply of values. The arguments specify how to generate values: the first argument is an initial value, the second specifies how to generate a new value from an existing one.
A supply of values that are in the
The initial value is 0, new values are generated by adding 1.
Create a new supply of values.
WARNING: This version is faster then
newSupply but it is not completely
thread safe, so use only if performance is an issue!
Rules for using the generated supplies:
* Supply splitting should be evaluated in a single thread.
For example, use case with
split2 to force the splitting
of a supply.
* Different threads should work with different supplies.
For example, one could (strictly) split a supply, and then
fork new threads with the resulting supplies.
Obtaining values from supplies
Generating new supplies from old
Split a supply into two different supplies. The resulting supplies are different from the input supply.
Split a supply into three different supplies.