foreign-var-0.1: Encapsulating mutatable state in external libraries

Copyright(c) 2014-2015 Edward Kmett
LicenseBSD2
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Foreign.Var

Contents

Description

 

Synopsis

Variables

data Var a Source

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 Vars only permit a very limited range of value assignments, and do not report failure.

Constructors

Var (IO a) (a -> IO ()) 

Instances

HasGetter (Var a) a 
HasSetter (Var a) a 
HasUpdate (Var a) a a 
Typeable (* -> *) Var 

mapVar :: (b -> a) -> (a -> b) -> Var a -> Var b Source

Change the type of a Var

newtype SettableVar a Source

Constructors

SettableVar (a -> IO ()) 

Instances

Classes

class HasSetter t a | t -> a where Source

Methods

($=) :: MonadIO m => t -> a -> m () infixr 2 Source

Instances

($=!) :: (HasSetter t a, MonadIO m) => t -> a -> m () infixr 2 Source

class HasSetter t a => HasUpdate t a b | t -> a b where Source

Minimal complete definition

Nothing

Methods

($~) :: MonadIO m => t -> (a -> b) -> m () infixr 2 Source

($~!) :: MonadIO m => t -> (a -> b) -> m () infixr 2 Source

Instances

Storable a => HasUpdate (Ptr a) a a 
HasUpdate (TVar a) a a 
HasUpdate (IORef a) a a 
HasUpdate (Var a) a a 

class HasGetter t a | t -> a where Source

Methods

get :: MonadIO m => t -> m a Source

Instances

HasGetter (IO a) a 
Storable a => HasGetter (Ptr a) a 
HasGetter (STM a) a 
HasGetter (TVar a) a 
HasGetter (IORef a) a 
HasGetter (Var a) a