tweak-0.1.0.1: A library for incremental computing

Safe HaskellNone

Control.Tweak.Var

Contents

Description

Var is the reference type used for incremental computing. It has a cached value and a list of dependent children to update when it changes.

The update propogation happens automatically when using either modifyVar or writeVar. Same with the STM variants.

Additionally updates can be triggered manually with update

Var is low level and is used by Tweakable and to create incremental expressions.

Synopsis

Reference for Incremental Computing

data Var a Source

This a reference for incremental computation. Not only does it include a value, But is also has a list of actions to execute when it is updated.

Constructors

Var 

Fields

_output :: TVar a

The cached value of the the Var

_children :: TVar Children

A collection of actions to execute when the value of the Var is updated

_identifier :: Unique

This is so to references to the same Var are not added to _children collection

Instances

Comply Maker Var 
Funktor Maker Var 
Eq (Var a)

Just checks pointer equality not value equality

Ord (Var a) 
Cacheable (Var a) 

Existential Var Wrapper

data AnyVar Source

Constructors

forall a . AnyVar (Var a) 

Helpers

type Update = STM ()Source

The type of update actions

type Children = Map AnyVar UpdateSource

The container for a Vars dependent Vars.

Lenses

output :: Lens (Var a) (Var b) (TVar a) (TVar b)Source

a Lens for the cached ref

identifier :: Lens (Var a) (Var a) Unique UniqueSource

a Lens for the unique identifier associated with this Var

Dependency Manipulation

update :: Cacheable a => a -> STM ()Source

Recursively call update on the children of a Var like thing

addChildSource

Arguments

:: Cacheable a 
=> a

The input that contains the reference to add children to

-> AnyVar

The child Var existentially wrapped up. The important info here is the unique Var id.

-> Update

The update action to call when the input is updated.

-> IO () 

Add a dependent child to the Vars children, or any type that has Var like Children See addChildSTM for the STM version

addChildSTMSource

Arguments

:: Cacheable a 
=> a

The input that contains the reference to add children to

-> AnyVar

The child Var existentially wrapped up. The important info here is the unique Var id.

-> Update

The update action to call when the input is updated.

-> STM () 

Add a dependent child to the Vars children, or any type that has Var like Children See addChild for the IO version

Var IO CRU

newVar :: a -> IO (Var a)Source

Create a new Var. See newVarSTM for the STM version.

readVar :: Var a -> IO aSource

Read the cached value of a Var. See readVarSTM for an STM version

modifyVar :: Var a -> (a -> a) -> IO ()Source

Modify a Var and update the children. See modifyVarSTM for the STM version

writeVar :: Var a -> a -> IO ()Source

Write a new value into a Var and update all of the children. See writeVarSTM for the STM version

Var STM CRU

newVarSTM :: a -> STM (Var a)Source

Create a new Var. See newVar for the IO version.

readVarSTM :: Var a -> STM aSource

Read the cached value of a Var. See readVar for an IO version

modifyVarSTM :: Var a -> (a -> a) -> STM ()Source

Modify a Var and update the children. See modifyVar for the IO version

writeVarSTM :: Var a -> a -> STM ()Source

Write a new value into a Var and update all of the children. See writeVar for the IO version