category-extras-0.53.6: Various modules and constructs inspired by category theoryContentsIndex
Control.Comonad.Supply
Portabilityportable
Stabilityprovisional
MaintainerEdward Kmett <ekmett@gmail.com>
Contents
Creating supplies
Obtaining values from supplies
Generating new supplies from old
Description

The technique for generating new values is based on the paper ''On Generating Unique Names'' by Lennart Augustsson, Mikael Rittri, and Dan Synek.

Integrated from value-supply-0.1

TODO: a SupplyT Comonad Transformer

Synopsis
module Control.Comonad
data Supply a
newSupply :: a -> (a -> a) -> IO (Supply a)
newEnumSupply :: Enum a => IO (Supply a)
newNumSupply :: Num a => IO (Supply a)
supplyValue :: Supply a -> a
supplyLeft :: Supply a -> Supply a
supplyRight :: Supply a -> Supply 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)
Documentation
module Control.Comonad
Creating supplies
data Supply a
A type that can be used to generate values on demand. A supply may be turned into two different supplies by using the functions supplyLeft and supplyRight.
show/hide Instances
newSupply :: a -> (a -> a) -> IO (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.
newEnumSupply :: Enum a => IO (Supply a)
A supply of values that are in the Enum class. The initial value is toEnum 0, new values are generates with succ.
newNumSupply :: Num a => IO (Supply a)
A supply of values that are in the Num class. The initial value is 0, new values are generated by adding 1.
Obtaining values from supplies
supplyValue :: Supply a -> a
Get the value of a supply. This function, together with modifySupply forms a comonad on Supply.
Generating new supplies from old
supplyLeft :: Supply a -> Supply a
Generate a new supply. This supply is different from the one generated with supplyRight.
supplyRight :: Supply a -> Supply a
Generate a new supply. This supply is different from the one generated with supplyLeft.
modifySupply :: Supply a -> (Supply a -> b) -> Supply b
Generate a new supply by systematically applying a function to an existing supply. This function, together with supplyValue form a comonad on Supply.
split :: Supply a -> [Supply a]
Generate an infinite list of supplies by using supplyLeft and supplyRight repeatedly.
split2 :: Supply a -> (Supply a, Supply a)
Split a supply into two different supplies. The resulting supplies are different from the input supply.
split3 :: Supply a -> (Supply a, Supply a, Supply a)
Split a supply into three different supplies.
split4 :: Supply a -> (Supply a, Supply a, Supply a, Supply a)
Split a supply into four different supplies.
Produced by Haddock version 2.1.0