Module Dynamic

Library for dynamic predicates. This paper contains a description of the basic ideas behind this library.

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

A dynamic predicate p with arguments of type t1,...,tn must be declared by:

p :: t1 -> ... -> tn -> Dynamic
p = dynamic

A dynamic predicate where all facts should be persistently stored in the directory DIR must be declared by:

p :: t1 -> ... -> tn -> Dynamic
p = persistent "file:DIR"

Remark: This library has been revised to the library Database. Thus, it might not be further supported in the future.

Author: Michael Hanus

Version: August 2011

Summary of exported operations:

dynamic :: a   
dynamic is only used for the declaration of a dynamic predicate and should not be used elsewhere.
persistent :: String -> a   
persistent is only used for the declaration of a persistent dynamic predicate and should not be used elsewhere.
(<>) :: Dynamic -> Dynamic -> Dynamic   
Combine two dynamics.
(|>) :: Dynamic -> Bool -> Dynamic   
Restrict a dynamic with a condition.
(|&>) :: Dynamic -> Bool -> Dynamic   
Restrict a dynamic with a constraint.
assert :: Dynamic -> IO ()   
Asserts new facts (without free variables!) about dynamic predicates.
retract :: Dynamic -> IO Bool   
Deletes facts (without free variables!) about dynamic predicates.
getKnowledge :: IO (Dynamic -> Bool)   
Returns the knowledge at a particular point of time about dynamic predicates.
getDynamicSolutions :: (a -> Dynamic) -> IO [a]   
Returns all answers to an abstraction on a dynamic expression.
getDynamicSolution :: (a -> Dynamic) -> IO (Maybe a)   
Returns an answer to an abstraction on a dynamic expression.
isKnown :: Dynamic -> IO Bool   
Returns True if there exists the argument facts (without free variables!) and False, otherwise.
transaction :: IO a -> IO (Maybe a)   
Perform an action (usually containing updates of various dynamic predicates) as a single transaction.
transactionWithErrorCatch :: IO a -> IO (Either a IOError)   
Perform an action (usually containing updates of various dynamic predicates) as a single transaction.
abortTransaction :: IO a   
Aborts the current transaction.

Exported datatypes:


Dynamic

The general type of dynamic predicates.

Constructors:


Exported operations:

dynamic :: a   

dynamic is only used for the declaration of a dynamic predicate and should not be used elsewhere.

persistent :: String -> a   

persistent is only used for the declaration of a persistent dynamic predicate and should not be used elsewhere.

(<>) :: Dynamic -> Dynamic -> Dynamic   

Combine two dynamics.

Further infos:
  • defined as right-associative infix operator with precedence 2
  • solution complete, i.e., able to compute all solutions

(|>) :: Dynamic -> Bool -> Dynamic   

Restrict a dynamic with a condition.

Further infos:
  • defined as left-associative infix operator with precedence 1
  • solution complete, i.e., able to compute all solutions

(|&>) :: Dynamic -> Bool -> Dynamic   

Restrict a dynamic with a constraint.

Further infos:
  • defined as left-associative infix operator with precedence 1
  • solution complete, i.e., able to compute all solutions

assert :: Dynamic -> IO ()   

Asserts new facts (without free variables!) about dynamic predicates. Conditional dynamics are asserted only if the condition holds.

retract :: Dynamic -> IO Bool   

Deletes facts (without free variables!) about dynamic predicates. Conditional dynamics are retracted only if the condition holds. Returns True if all facts to be retracted exist, otherwise False is returned.

getKnowledge :: IO (Dynamic -> Bool)   

Returns the knowledge at a particular point of time about dynamic predicates. If other processes made changes to persistent predicates, these changes are read and made visible to the currently running program.

getDynamicSolutions :: (a -> Dynamic) -> IO [a]   

Returns all answers to an abstraction on a dynamic expression. If other processes made changes to persistent predicates, these changes are read and made visible to the currently running program.

getDynamicSolution :: (a -> Dynamic) -> IO (Maybe a)   

Returns an answer to an abstraction on a dynamic expression. Returns Nothing if no answer exists. If other processes made changes to persistent predicates, these changes are read and made visible to the currently running program.

isKnown :: Dynamic -> IO Bool   

Returns True if there exists the argument facts (without free variables!) and False, otherwise.

transaction :: IO a -> IO (Maybe a)   

Perform an action (usually containing updates of various dynamic predicates) as a single transaction. This is the preferred way to execute any changes to persistent dynamic predicates if there might be more than one process that may modify the definition of such predicates in parallel.

Before the transaction is executed, the access to all persistent predicates is locked (i.e., no other process can perform a transaction in parallel). After the successful transaction, the access is unlocked so that the updates performed in this transaction become persistent and visible to other processes. Otherwise (i.e., in case of a failure or abort of the transaction), the changes of the transaction to persistent predicates are ignored and Nothing is returned.

In general, a transaction should terminate and all failures inside a transaction should be handled (execept for abortTransaction). If a transaction is externally interrupted (e.g., by killing the process), some locks might never be removed. However, they can be explicitly removed by deleting the corresponding lock files reported at startup time.

Nested transactions are not supported and lead to a failure.

transactionWithErrorCatch :: IO a -> IO (Either a IOError)   

Perform an action (usually containing updates of various dynamic predicates) as a single transaction. This is similar to transaction but an execution error is caught and returned instead of printing it.

abortTransaction :: IO a   

Aborts the current transaction. If a transaction is aborted, the remaining actions of the transaction are not executed and all changes to persistent dynamic predicates made in this transaction are ignored.

abortTransaction should only be used in a transaction. Although the execution of abortTransaction always fails (basically, it writes an abort record in log files, unlock them and then fails), the failure is handled inside transaction.

Further infos:
  • externally defined