Next Previous Contents

2. Interface of the Module SVars

This module provides a simple form of single assignment variables. The following type represents single assignment variables.

data V a

Single assignment variables can only be created within the IO monad; otherwise, referential transparency would be compromised.

newV :: IO (V a)

However, the value of a single assignment variables can be accessed outside of the monad. This is save, as single assignment variables are only instantiated monotonically, i.e., once such a variable is bound, the value can never change again.

valV :: V a -> a

If a single assignment variable is accessed while no value is yet bound to the variable, the thread accessing the variable is suspended. Only when the variable is, eventually, bound, the reading thread is allowed to continue. Thus, a computation can never observe an unbound single assignment variable, which together with the monotonicity (mentioned above) guarantees referential transparency.

Single assignment variables can be bound within the IO monad with an expression of the form svar << value, where svar is a single assignment variable and value the value that is to be associated with the variable

(<<) :: V a -> a -> IO ()

Furthermore, this module provides a symmetric fork/join operation:

(&) :: IO a -> IO b -> IO (a, b)

The operation models parallel composition, which terminates after both of the concurrent subcomputations terminated.

Next Previous Contents