Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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
- data Prop a
- newProp :: a -> IO (Prop a)
- newConstProp :: a -> IO (Prop a)
- freezeProp :: Prop a -> IO ()
- readProp :: Prop a -> IO a
- watchProp :: Prop a -> IO () -> IO ()
- setProp :: POrder a => Prop a -> IO a -> IO ()
- lift1 :: POrder b => (a -> b) -> Prop a -> Prop b -> IO ()
- lift2 :: POrder c => (a -> b -> c) -> Prop a -> Prop b -> Prop c -> IO ()
- liftList :: POrder b => ([a] -> b) -> [Prop a] -> Prop b -> IO ()
Documentation
A cell in a propagator network
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).
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