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.
C x1 . . . xn == D y1 . . . ym = False % for all different constructors C and D<br />
This implements a test for strict equality (cf. Section 2.6). For instance, the test “[0]==[0]”<br />
reduces to True, whereas the test “1==0” reduces to False. <strong>An</strong> equality test with a free variable in<br />
one side is delayed in order to avoid an infinite set of solutions for insufficiently instantiated tests<br />
like x==y. Usually, strict equality is only defined on data terms, i.e., == is not really polymorphic<br />
but an overloaded function symbol. This could be more precisely expressed using type classes which<br />
will be considered in a future version.<br />
Note that e1==e2 only tests the identity of e1 and e2 but never binds one side to the other if it<br />
is a free variable. This is in contrast to solving the equational constraint e1=:=e2 which is checked<br />
for satisfiability and propagates new variable bindings in order to solve this constraint. Thus, in<br />
terms of concurrent constraint programming languages [44], == and =:= correspond to ask and tell<br />
equality constraints, respectively.<br />
4.1.2 Constraints<br />
The type Success is the result type of expressions used in conditions of defining rules. Since<br />
conditions must be successfully evaluated in order to apply the rule, the type Success can be also<br />
interpreted as the type of successful evaluations. A function with result type Success is also called<br />
a constraint.<br />
Constraints are different from Boolean-valued functions: a Boolean expression reduces to True<br />
or False whereas a constraint is checked for satisfiability. A constraint is applied (i.e., solved) in a<br />
condition of a conditional equation. The equational constraint e1=:=e2 is an elementary constraint<br />
which is solvable if the expressions e1 and e2 are evaluable to unifiable data terms. success denotes<br />
an always solvable constraint.<br />
Constraints can be combined into a conjunction of the form c1 & c2 & . . . & cn by applying the<br />
concurrent conjunction operator &. In this case, all constraints in the conjunction are evaluated<br />
concurrently. Constraints can also be evaluated in a sequential order by the sequential conjunction<br />
operator &>, i.e., the combined constraint c1 &> c2 will be evaluated by first completely evaluating<br />
c1 and then c2.<br />
Constraints can be passed as parameters or results of functions like any other data object. For<br />
instance, the following function takes a list of constraints as input and produces a single constraint,<br />
the concurrent conjunction of all constraints of the input list:<br />
conj :: [Success] -> Success<br />
conj [] = success<br />
conj (c:cs) = c & conj cs<br />
The trivial constraint success is usually not shown in answers to a constraint expression. For<br />
instance, the constraint x*x=:=y & x=:=2 is evaluated to the answer<br />
{x=2, y=4}<br />
15