rec-def-0.2.2: Recursively defined values
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Propagator.Naive

Description

A very naive propagator library.

This propagator implementation keeps updating the values accoring to their definitions as other values change, until a fixed-point is reached.

It is a naive implementation and not very clever. Much more efficient propagator implementations are possible, and may be used by this library in the future.

Synopsis

Documentation

data Prop a Source #

A cell in a propagator network

Instances

Instances details
Bottom a => Propagator (Prop a) a Source # 
Instance details

Defined in Data.Propagator.Naive

Methods

newProp :: IO (Prop a) Source #

newConstProp :: a -> IO (Prop a) Source #

freezeProp :: Prop a -> IO () Source #

readProp :: Prop a -> IO a Source #

newProp :: a -> IO (Prop a) Source #

Creates a cell, initialized to bottom

newConstProp :: a -> IO (Prop a) Source #

Creates a constant cell, given an initial value

freezeProp :: Prop a -> IO () Source #

Marks the propagator as frozen.

Will prevent further calls to setProp and clears the list of watchers (to allow GC).

readProp :: Prop a -> IO a Source #

Reads the current value of the cell

watchProp :: Prop a -> IO () -> IO () Source #

Watch a cell: If the value changes, the given action is executed

setProp :: POrder a => Prop a -> IO a -> IO () Source #

Sets a new value calculated from the given action. The action is executed atomically.

Throws if the propagator is already frozen

If the value has changed, all watchers are notified afterwards (not atomically).

lift1 :: POrder b => (a -> b) -> Prop a -> Prop b -> IO () Source #

Whenever the first cell changes, update the second, using the given function

lift2 :: POrder c => (a -> b -> c) -> Prop a -> Prop b -> Prop c -> IO () Source #

Whenever any of the first two cells change, update the third, using the given function

liftList :: POrder b => ([a] -> b) -> [Prop a] -> Prop b -> IO () Source #

Whenever any of the cells in the list change, update the other, using the given function