Copyright | (c) 2014-2015 Edward Kmett |
---|---|
License | BSD2 |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Foreign.Var
Description
- data Var a = Var {}
- newVar :: IO a -> (a -> IO ()) -> Var a
- mapVar :: (b -> a) -> (a -> b) -> Var a -> Var b
- newtype SettableVar a = SettableVar (a -> IO ())
- type GettableVar = IO
- class HasSetter t a | t -> a where
- ($=!) :: (HasSetter t a, MonadIO m) => t -> a -> m ()
- class HasSetter t a => HasUpdate t a b | t -> a b where
- class HasGetter t a | t -> a where
Variables
This data type represents a piece of mutable, imperative state with possible side-effects. These tend to encapsulate all sorts tricky behavior in external libraries, and may well throw exceptions.
Inhabitants should satsify the following properties.
In the absence of concurrent mutation from other threads or a thrown exception:
do x <-getVar
v;setVar
v y;setVar
v x
should restore the previous state.
Ideally, in the absence of thrown exceptions:
setVar
v a >>getVar
v
should return a
, regardless of a
. In practice some Var
s only
permit a very limited range of value assignments, and do not report failure.
The result of updateVar
should also be compatible with the result of getting
and setting separately, however, it may be more efficient or have better
atomicity properties in a concurrent setting.
Constructors
Var | |
Build a Var
form a getter and a setter.
newtype SettableVar a Source
Constructors
SettableVar (a -> IO ()) |
Instances
HasSetter (SettableVar a) a | |
Typeable (* -> *) SettableVar |
type GettableVar = IO Source