Module Control.AllValues

Library with operations to encapsulate search, i.e., non-deterministic computations. Note that some of these operations are not fully declarative, i.e., the results depend on the order of evaluation and program rules. There are newer and better approaches the encapsulate search, in particular, set functions (see module Control.SetFunctions in package setfunctions), which should be used.

Author: Michael Hanus

Version: September 2023

Summary of exported operations:

getAllValues :: a -> IO [a]  Deterministic 
Gets all values of an expression (similarly to Prolog's findall).
getOneValue :: a -> IO (Maybe a)  Deterministic 
Gets one value of an expression.
getAllFailures :: a -> (a -> Bool) -> IO [a]  Deterministic 
Returns a list of values that do not satisfy a given constraint.
allValues :: a -> [a]  Deterministic 
Returns all values of an expression.
oneValue :: a -> Maybe a  Deterministic 
Returns just one value for an expression.
someValue :: a -> a  Deterministic 
Returns some value for an expression.
isFail :: a -> Bool  Deterministic 
Does the computation of the argument to a head-normal form fail? Conceptually, the argument is evaluated on a copy, i.e., even if the computation does not fail, it has not been evaluated.
rewriteAll :: a -> [a]  Deterministic 
Gets all values computable by term rewriting.
rewriteSome :: a -> Maybe a  Deterministic 
Similarly to rewriteAll but returns only some value computable by term rewriting.

Exported operations:

getAllValues :: a -> IO [a]  Deterministic 

Gets all values of an expression (similarly to Prolog's findall). Conceptually, the value is computed on a copy of the expression, i.e., the evaluation of the expression does not share any results. In PAKCS, the evaluation suspends as long as the expression contains unbound variables or the computed value contains unbound variables.

getOneValue :: a -> IO (Maybe a)  Deterministic 

Gets one value of an expression. Returns Nothing if the search space is finitely failed. Conceptually, the value is computed on a copy of the expression, i.e., the evaluation of the expression does not share any results. In PAKCS, the evaluation suspends as long as the expression contains unbound variables or the computed value contains unbound variables.

getAllFailures :: a -> (a -> Bool) -> IO [a]  Deterministic 

Returns a list of values that do not satisfy a given constraint.

Example call:
(getAllFailures x c)
Parameters:
  • x : an expression (a generator evaluable to various values)
  • c : a constraint that should not be satisfied
Returns:
A list of all values of e such that (c e) is not provable

allValues :: a -> [a]  Deterministic 

Returns all values of an expression. Conceptually, the value is computed on a copy of the expression, i.e., the evaluation of the expression does not share any results. In PAKCS, the evaluation suspends as long as the expression contains unbound variables or the computed value contains unbound variables.

Note that this operation is not purely declarative since the ordering of the computed values depends on the ordering of the program rules.

Further infos:
  • externally defined

oneValue :: a -> Maybe a  Deterministic 

Returns just one value for an expression. If the expression has no value, Nothing is returned. Conceptually, the value is computed on a copy of the expression, i.e., the evaluation of the expression does not share any results. In PAKCS, the evaluation suspends as long as the expression contains unbound variables or the computed value contains unbound variables.

Note that this operation is not purely declarative since the computed value depends on the ordering of the program rules. Thus, this operation should be used only if the expression has a single value.

Further infos:
  • externally defined

someValue :: a -> a  Deterministic 

Returns some value for an expression. If the expression has no value, the computation fails. Conceptually, the value is computed on a copy of the expression, i.e., the evaluation of the expression does not share any results. In PAKCS, the evaluation suspends as long as the expression contains unbound variables or the computed value contains unbound variables.

Note that this operation is not purely declarative since the computed value depends on the ordering of the program rules. Thus, this operation should be used only if the expression has a single value.

Further infos:
  • partially defined

isFail :: a -> Bool  Deterministic 

Does the computation of the argument to a head-normal form fail? Conceptually, the argument is evaluated on a copy, i.e., even if the computation does not fail, it has not been evaluated.

rewriteAll :: a -> [a]  Deterministic 

Gets all values computable by term rewriting. In contrast to allValues, this operation does not wait until all "outside" variables are bound to values, but it returns all values computable by term rewriting and ignores all computations that requires bindings for outside variables.

Further infos:
  • externally defined

rewriteSome :: a -> Maybe a  Deterministic 

Similarly to rewriteAll but returns only some value computable by term rewriting. Returns Nothing if there is no such value.

Further infos:
  • externally defined