Curry: An Integrated Functional Logic Language
Curry: An Integrated Functional Logic Language
Curry: An Integrated Functional Logic Language
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
do line do stmts<br />
expr >>= \p -> do stmts<br />
let decls<br />
in do stmts<br />
Global search, possibly implemented by backtracking, must be avoided in some situations (usercontrol<br />
of efficiency, concurrent computations, non-backtrackable I/O). Hence it is sometimes necessary<br />
to encapsulate search, i.e., non-deterministic computations in parts of larger programs.<br />
Non-deterministic computations might occur in <strong>Curry</strong> whenever a function must be evaluated with<br />
a free variable at a flexible argument position. In this case, the computation must follow different<br />
branches with different bindings applied to the current expression which has the effect that the<br />
entire expression is split into (at least) two independent disjunctions. To give the programmer control<br />
on the actions taken in this situation, <strong>Curry</strong> provides a primitive search operator which is the<br />
basis to implement sophisticated search strategies. This section sketches the idea of encapsulating<br />
search in <strong>Curry</strong> and describes some predefined search strategies.<br />
8.1 Search Goals and Search Operators<br />
Since search is used to find solutions to some constraint, search is always initiated by a constraint<br />
containing a search variable for which a solution should be computed. 11 Since the search variable<br />
may be bound to different solutions in different disjunctive branches, it must be abstracted.<br />
Therefore, a search goal has the type a->Success where a is the type of the values which we are<br />
searching for. In particular, if c is a constraint containing a variable x and we are interested in<br />
solutions for x, i.e., values for x such that c is satisfied, then the corresponding search goal has the<br />
form \x->c. However, any other expression of the same type can also be used as a search goal.<br />
To control the search performed to find solutions to search goals, <strong>Curry</strong> has a predefined operator<br />
try :: (a->Success) -> [a->Success]<br />
11 The generalization to more than one search variable is straightforward by the use of tuples.<br />
29