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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

such cases, anonymous functions (λ-abstractions), denoted by<br />

\x1 . . . xn->e<br />

are provided.<br />

3 Operational Semantics<br />

<strong>Curry</strong>’s operational semantics is based on the lazy evaluation of expressions combined with a possible<br />

instantiation of free variables occurring in the expression. If the expression is ground, the<br />

operational model is similar to lazy functional languages, otherwise (possibly non-deterministic)<br />

variable instantiations are performed as in logic programming. If an expression contains free variables,<br />

it may be reduced to different values by binding the free variables to different expressions.<br />

In functional programming, one is interested in the computed value, whereas logic programming<br />

emphasizes the different bindings (answers). Thus, we define for the integrated functional logic<br />

language <strong>Curry</strong> an answer expression as a pair “σ e” consisting of a substitution σ (the answer<br />

computed so far) and an expression e. <strong>An</strong> answer expression σ e is solved if e is a data term.<br />

Usually, the identity substitution in answer expressions is omitted, i.e., we write e instead of {} e<br />

if it is clear from the context.<br />

Since more than one answer may exist for expressions containing free variables, in general, initial<br />

expressions are reduced to disjunctions of answer expressions. Thus, a disjunctive expression is a<br />

(multi-)set of answer expressions {σ1 e1, . . . , σn en}. For the sake of readability, we write concrete<br />

disjunctive expressions like<br />

{{x = 0, y = 2} 2 , {x = 1, y = 2} 3}<br />

in the form {x=0,y=2} 2 | {x=1,y=2} 3. Thus, substitutions are represented by lists of equations<br />

enclosed in curly brackets, and disjunctions are separated by vertical bars.<br />

A single computation step performs a reduction in exactly one unsolved expression of a disjunction<br />

(e.g., in the leftmost unsolved answer expression in Prolog-like implementations). If the<br />

computation step is deterministic, the expression is reduced to a new one. If the computation step<br />

is non-deterministic, the expression is replaced by a disjunction of new expressions. The precise<br />

behavior depends on the function calls occurring in the expression. For instance, consider the<br />

following rules:<br />

f 0 = 2<br />

f 1 = 3<br />

The result of evaluating the expression f 1 is 3, whereas the expression f x should be evaluated<br />

to the disjunctive expression<br />

{x=0} 2 | {x=1} 3 .<br />

To avoid superfluous computation steps and to apply programming techniques of modern functional<br />

languages, nested expressions are evaluated lazily, i.e., the leftmost outermost function call is<br />

primarily selected in a computation step. Due to the presence of free variables in expressions, this<br />

function call may have a free variable at an argument position where a value is demanded by the<br />

left-hand sides of the function’s rules (a value is demanded by an argument position of the left-hand<br />

12

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

Saved successfully!

Ooh no, something went wrong!