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 |
- data Var a = Var (IO a) (a -> IO ())
- 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 <-get
v; v$=
y; v$=
x
should restore the previous state.
Ideally, in the absence of thrown exceptions:
v$=
a >>get
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.
newtype SettableVar a Source
SettableVar (a -> IO ()) |
HasSetter (SettableVar a) a | |
Typeable (* -> *) SettableVar |
type GettableVar = IO Source