14.11.2012 Views

Curry: An Integrated Functional Logic Language

Curry: An Integrated Functional Logic Language

Curry: An Integrated Functional Logic Language

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

one (“generate and test”). This can be expressed by solving the following goal: 13<br />

coloring l1 l2 l3 l4 & correct l1 l2 l3 l4<br />

However, a much faster solution can be obtained by reversing the order of the tester and the<br />

generator:<br />

correct l1 l2 l3 l4 & coloring l1 l2 l3 l4<br />

The latter constraint is evaluated in a concurrent way. In the first steps, the subexpression<br />

correct l1 l2 l3 l4 is reduced to the constraint<br />

diff l1 l2 & diff l1 l3 & diff l2 l3 & diff l2 l4 & diff l3 l4<br />

which is then reduced to<br />

(l1==l2)=:=False & (l1==l3)=:=False & (l2==l3)=:=False & (l2==l4)=:=False<br />

& (l3==l4)=:=False<br />

This constraint cannot be further evaluated since the arguments to == are free variables. Therefore,<br />

it is suspended and the final equational constraint coloring l1 l2 l3 l4 is evaluated which binds<br />

the variables to the potential colors. Since the variable binding is performed by consecutive computation<br />

steps, the equalities are evaluated as soon as their arguments are bound. For instance, if the<br />

variables l1 and l2 are bound to the color Red, the first constraint (l1==l2)=:=False cannot be<br />

solved (due to the unsolvability of the equational constraint True=:=False) which causes the failure<br />

of the entire goal. As a consequence, not all potential colorings are computed (as in the generateand-test<br />

approach) but only those colorings for which the constraints correct l1 l2 l3 l4 is<br />

satisfiable. Therefore, the (dis)equality goals act as “passive constraints” aiming to reduce the<br />

search space.<br />

13 We assume an implementation that processes the concurrent conjunction c1 & c2 in a “sequential-first” manner:<br />

first c1 is solved and, if this is not possible due to a suspended evaluation, c2 is solved.<br />

43

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!