Module GlobalVariable

Library for handling global variables. A global variable has a name declared in the program. Its value (a data term possibly containing free variables) can be accessed and modified by IO actions.

In contast to global entities (as defined in the library Global), global variables can contain logic variables shared with computations running in the same computation space. As a consequence, global variables cannot be persistent, their values are not kept across different program executions.

Currently, it is still experimental so that its interface might be slightly changed in the future.

A global variable g with an initial value v of type t must be declared by:

g :: GVar t
g = gvar v

Here, the type t must not contain type variables. v is the initial value for every program run.

Note: the implementation in PAKCS is based on threading a state through the execution. Thus, it might be the case that some updates of global variables are lost if fancy features like unsafe operations or debugging support are used.

Author: Michael Hanus

Version: March 2010

Summary of exported operations:

gvar :: a -> GVar a   
gvar is only used for the declaration of a global variable and should not be used elsewhere.
readGVar :: GVar a -> IO a   
Reads the current value of a global variable.
writeGVar :: GVar a -> a -> IO ()   
Updates the value of a global variable.

Exported datatypes:


GVar

The general type of global variables.

Constructors:


Exported operations:

gvar :: a -> GVar a   

gvar is only used for the declaration of a global variable and should not be used elsewhere. In the future, it might become a keyword.

Further infos:
  • solution complete, i.e., able to compute all solutions

readGVar :: GVar a -> IO a   

Reads the current value of a global variable.

writeGVar :: GVar a -> a -> IO ()   

Updates the value of a global variable. The associated term is evaluated to a data term and might contain free variables.