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.
D Operational Semantics of <strong>Curry</strong><br />
The precise specification of the operational semantics of <strong>Curry</strong> is based on the evaluation annotation<br />
and the patterns on the rules’ left-hand sides for each function. Therefore, we describe the<br />
computation model by providing a precise definition of pattern matching with evaluation annotations<br />
(Section D.1) which is the basis to define the computation steps on expressions (Section D.2).<br />
The extension of this basic computation model to solving equational constraints and higher-order<br />
functions is described in Sections D.4 and D.5, respectively. Section D.6 describes the automatic<br />
generation of the definitional trees to guide the pattern matching strategy. Finally, Section D.7<br />
specifies the operational semantics of the primitive operator try for encapsulating search.<br />
D.1 Definitional Trees<br />
We start by considering only the unconditional first-order part of <strong>Curry</strong>, i.e., rules do not contain<br />
conditions and λ-abstractions and partial function applications are not allowed. We assume some<br />
familiarity with basic notions of term rewriting [14] and functional logic programming [21].<br />
We denote by C the set of constructors (with elements c, d), by F the set of defined functions<br />
or operations (with elements f, g), and by X the set of variables (with elements x, y), where C, F<br />
and X are disjoint. <strong>An</strong> expression (data term) is a variable x ∈ X or an application ϕ(e1, . . . , en)<br />
where ϕ ∈ C ∪ F (ϕ ∈ C) has arity n and e1, . . . , en are expressions (data terms). 17 The set of all<br />
expressions and data terms are denoted by T (C ∪ F, X ) and T (C, X ), respectively. A call pattern<br />
is an expression of the form f(t1, . . . , tn) where each variable occurs only once, f ∈ F is an n-ary<br />
function, and t1, . . . , tn ∈ T (C, X ). root(e) denotes the symbol at the root of the expression e.<br />
A position p in an expression e is represented by a sequence of natural numbers, e|p denotes the<br />
subterm or subexpression of e at position p, and e[e ′ ]p denotes the result of replacing the subterm<br />
e|p by the expression e ′ (see [14] for details).<br />
A substitution is a mapping σ: X → T (C ∪ F, X ) with σ(x) �= x only for finitely many variables<br />
x. Thus, we denote a substitution by σ = {x1 ↦→ t1, . . . , xn ↦→ tn}, where σ(xi) �= xi for i = 1, . . . , n,<br />
and id denotes the identity substitution (n = 0). Dom(σ) = {x1, . . . , xn} is the domain of σ and<br />
VRan(σ) = {x | x is a variable occurring in some ti, i ∈ {1, . . . , n}}<br />
is its variable range. Substitutions are extended to morphisms on expressions by σ(f(e1, . . . , en)) =<br />
f(σ(e1), . . . , σ(en)) for every expression f(e1, . . . , en).<br />
A <strong>Curry</strong> program is a set of rules l = r satisfying some restrictions (see Section 2.3). In particular,<br />
the left-hand side l must be a call pattern. A rewrite rule is called a variant of another rule if it is<br />
obtained by a unique replacement of variables by other variables.<br />
<strong>An</strong> answer expression is a pair σ e consisting of a substitution σ (the answer computed so far)<br />
and an expression e. <strong>An</strong> answer expression σ e is solved if e is a data term. We sometimes omit<br />
the identity substitution in answer expressions, i.e., we write e instead of id e if it is clear from the<br />
context. A disjunctive expression is a (multi-)set of answer expressions {σ1 e1, . . . , σn en}. The<br />
set of all disjunctive expressions is denoted by D.<br />
17 Since we do not consider partial applications in this part, we write the full application as ϕ(e1, . . . , en) which is<br />
equivalent to <strong>Curry</strong>’s notation ϕ e1 . . . en.<br />
64