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.

tified variable (and, thus, it can only occur in front of a constraint) whereas other let declarations<br />

introduce local functions or parameters. Since all local declarations can be mutually recursive, it<br />

is also possible to use local variables in the bodies of the local functions in one let declarations.<br />

For instance, the following expression is valid (where the functions h and k are defined elsewhere):<br />

let f x = h x y<br />

y free<br />

g z = k y z<br />

in c y (f (g 1))<br />

Similarly to the usual interpretation of local definitions by lambda lifting [29], this expression can<br />

be interpreted by transforming the local definitions for f and g into global ones by adding the<br />

non-local variables of the bodies as parameters:<br />

f y x = h x y<br />

g y z = k y z<br />

...<br />

let y free in c y (f y (g y 1))<br />

See Appendix D.8 for more details about the meaning and transformation of local definitions.<br />

2.6 Constraints and Equality<br />

A condition of a rule is a constraint which must be solved in order to apply the rule. <strong>An</strong> elementary<br />

constraint is an equational constraint e1=:=e2 between two expressions (of base type). e1=:=e2 is<br />

satisfied if both sides are reducible to a same ground data term. This notion of equality, which is<br />

the only sensible notion of equality in the presence of non-terminating functions [17, 37] and also<br />

used in functional languages, is also called strict equality. As a consequence, if one side is undefined<br />

(nonterminating), then the strict equality does not hold. Operationally, an equational constraint<br />

e1=:=e2 is solved by evaluating e1 and e2 to unifiable data terms. The equational constraint could<br />

also be solved in an incremental way by an interleaved lazy evaluation of the expressions and<br />

binding of variables to constructor terms (see [33] or Section D.4 in the appendix).<br />

Equational constraints should be distinguished from standard Boolean functions (cf. Section 4.1)<br />

since constraints are checked for satisfiability. For instance, the equational constraint [x]=:=[0]<br />

is satisfiable if the variable x is bound to 0. However, the evaluation of [x]=:=[0] does not<br />

deliver a Boolean value True or False, since the latter value would require a binding of x to all<br />

values different from 0 (which could be expressed if a richer constraint system than substitutions,<br />

e.g., disequality constraints [7], is used). This is sufficient since, similarly to logic programming,<br />

constraints are only activated in conditions of equations which must be checked for satisfiability.<br />

Note that the basic kernel of <strong>Curry</strong> only provides strict equations e1=:=e2 between expressions<br />

as elementary constraints. Since it is conceptually fairly easy to add other constraint structures [35],<br />

extensions of <strong>Curry</strong> may provide richer constraint systems to support constraint logic programming<br />

applications.<br />

Constraints can be combined into a conjunction written as c1 & c2. The conjunction is interpreted<br />

concurrently: if the combined constraint c1 & c2 should be solved, c1 and c2 are solved<br />

concurrently. In particular, if the evaluation of c1 suspends, the evaluation of c2 can proceed which<br />

10

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

Saved successfully!

Ooh no, something went wrong!