Module Data.Global

A library to support global entities in Curry programs. A global entity has a name declared as a top-level entity. Its value can be accessed and modified by IO actions. Furthermore, global entities can be declared as persistent so that their values are stored across different program executions or temporary so that they will be stored only in memory.

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

A temporary global entity gt is a top-level constant of type GlobalT t. If v is an initial value v of type t, where the type t does not contain type variables or type class contraints, the temporary global entity could be declared by:

gt :: GlobalT t
gt = globalTemporary v

Similarly, a persistent global entity gp with an initial value v of type t could be declared by:

gt :: GlobalP t
gt = globalPersistent f v

where the type t must not contain type variables and support Read and Show instances. f is the file name where the global value is persistently stored (the file is created and initialized with v if it does not exist).

Author: Michael Hanus

Version: April 2021

Summary of exported operations:

globalTemporary :: a -> GlobalT a  Deterministic 
globalTemporary is only used to declare a temporary global value as a top-level entity.
readGlobalT :: GlobalT a -> IO a  Deterministic 
Reads the current value of a temporary global entity.
writeGlobalT :: GlobalT a -> a -> IO ()  Deterministic 
Updates the value of a temporary global entity.
globalPersistent :: (Read a, Show a) => String -> a -> GlobalP a  Deterministic 
globalPersistent is only used declare a persistent global value as a top-level entity.
readGlobalP :: Read a => GlobalP a -> IO a  Deterministic 
Reads the current value of a persistent global entity.
safeReadGlobalP :: (Read a, Show a) => GlobalP a -> a -> IO a  Deterministic 
Safely reads the current value of a global.
writeGlobalP :: Show a => GlobalP a -> a -> IO ()  Deterministic 
Updates the value of a persistent global entity.

Exported datatypes:


GlobalT

The abstract type of a temporary global entity.

Constructors:


GlobalP

The abstract type of a persistent global entity.

Constructors:


Exported operations:

globalTemporary :: a -> GlobalT a  Deterministic 

globalTemporary is only used to declare a temporary global value as a top-level entity. It should not be used elsewhere.

readGlobalT :: GlobalT a -> IO a  Deterministic 

Reads the current value of a temporary global entity.

writeGlobalT :: GlobalT a -> a -> IO ()  Deterministic 

Updates the value of a temporary global entity.

globalPersistent :: (Read a, Show a) => String -> a -> GlobalP a  Deterministic 

globalPersistent is only used declare a persistent global value as a top-level entity. It should not be used elsewhere. The first argument is the file name where the global value is persistently stored. The file is created and initialized with the second argument if it does not exist.

readGlobalP :: Read a => GlobalP a -> IO a  Deterministic 

Reads the current value of a persistent global entity.

safeReadGlobalP :: (Read a, Show a) => GlobalP a -> a -> IO a  Deterministic 

Safely reads the current value of a global. If readGlobalP fails (e.g., due to a corrupted persistent storage), the global is re-initialized with the default value given as the second argument.

writeGlobalP :: Show a => GlobalP a -> a -> IO ()  Deterministic 

Updates the value of a persistent global entity.