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.

Computation step for a single expression:<br />

Eval [ei ] ⇒ D<br />

Eval [e1 & e2 ] ⇒ replace(e1 & e2, i, D)<br />

i ∈ {1, 2}<br />

Eval [ei ] ⇒ D<br />

Eval [c(e1, . . . , en)] ⇒ replace(c(e1, . . . , en), i, D)<br />

Eval [f(e1, . . . , en); T ] ⇒ D<br />

Eval [f(e1, . . . , en)] ⇒ D<br />

i ∈ {1, . . . , n}<br />

if T is a definitional tree for f with fresh variables<br />

Computation step for an operation-rooted expression e:<br />

Eval [e; rule(l = r)] ⇒ {id σ(r)}<br />

Eval [e; T1 ] ⇒ D1 Eval [e; T2 ] ⇒ D2<br />

Eval [e; or(T1, T2)] ⇒ D1 ∪ D2<br />

if σ is a substitution with σ(l) = e<br />

Eval [e; branch(π, p, r, T1, . . . , Tk)] ⇒<br />

⎧<br />

D if e|p = c(e1, . . . , en), pat(Ti)|p = c(x1, . . . , xn), and Eval [e; Ti ] ⇒ D<br />

⎪⎨<br />

∅ if e|p = c(· · ·) and pat(Ti)|p �= c(· · ·), i = 1, . . . , k<br />

�k ⎪⎩ i=1 {σi σi(e)} if e|p = x, r = flex, and σi = {x ↦→ pat(Ti)|p}<br />

replace(e, p, D) if e|p = f(e1, . . . , en) and Eval [e|p ] ⇒ D<br />

Derivation step for a disjunctive expression:<br />

Eval [e] ⇒ {σ1 e1, . . . , σn en}<br />

{σ e} ∪ D ⇒ {σ1 ◦ σ e1, . . . , σn ◦ σ en} ∪ D<br />

D.2 Computation Steps<br />

Figure 2: Operational semantics of <strong>Curry</strong><br />

The operational semantics is defined by the derivability relation D1 ⇒ D2 on disjunctive expressions<br />

specified in Figure 2. <strong>An</strong> inference rule α<br />

should be read as “if α is derivable, then β is also<br />

β<br />

derivable”. We say that the computation of an expression e suspends if there is no D with Eval [e] ⇒<br />

D. A constraint is solvable if it can be reduced to success. The exact method to solve constraints<br />

depends on the constraint solver. A method to solve equational constraints on data terms is<br />

specified in Section D.4. For the purpose of this definition, we consider success as the neutral<br />

element of the operation &, i.e., success & c and c & success are considered as equivalent to c.<br />

As can be seen by the rules for evaluating constraints in Figure 2, the concurrent conjunction<br />

of two constraints is evaluated by applying computation steps to one of the two constraints. Since<br />

both constraints must be finally solved (i.e., reduced to success), one can consider the evaluation<br />

of a concurrent conjunction as two computation threads evaluating these constraints. They<br />

are synchronized by accessing common variables (which may suspend a thread, see below). In a<br />

simple sequential implementation, the evaluation of e1 & e2 could be started by an attempt to solve<br />

e1. If the evaluation of e1 suspends, an evaluation step is applied to e2. If a variable responsible<br />

66

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

Saved successfully!

Ooh no, something went wrong!