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.

D.8 Eliminating Local Declarations<br />

In the description of the operational semantics above, we assumed that a <strong>Curry</strong> program is a set<br />

of rules l = r where the left-hand side l is a call pattern and the right-hand side r is an expression<br />

containing variables, constructors, and defined functions. However, a <strong>Curry</strong> program can also<br />

contain local declarations (cf. Section 2.4) whose operational semantics is not defined so far. To<br />

simplify the operational semantics, we do not extend it to local declarations but provide in the<br />

following a transformation of <strong>Curry</strong> programs containing local declarations into <strong>Curry</strong> programs<br />

without local declarations (except for free variables). The main purpose of this transformation is to<br />

provide a precise definition of the operational semantics of the full language. This transformation<br />

can also be performed by implementations of <strong>Curry</strong> but it is also possible that some implementations<br />

provide explicit support for local declarations, provided that they satisfy the operational meaning<br />

described in the following.<br />

The elimination of local function and pattern declarations is done by the following steps which<br />

are subsequently described in more detail:<br />

1. Eliminate sections and lambda abstractions<br />

2. Eliminate Boolean guards in rules<br />

3. Transform where declarations into let declarations<br />

4. Eliminate local patterns and functions<br />

For the following, we assume that all name conflicts have been resolved, i.e., the names of functions<br />

and argument variables defined in the different declarations are pairwise different.<br />

Eliminate sections and lambda abstractions:<br />

Each left section (expr op) is transformed into the partial application ((op) expr).<br />

Each right section (op expr) is transformed into the lambda abstraction (\x->(op) x expr)<br />

where x is a new variable.<br />

All λ-abstractions are eliminated by providing a new name (cf. Section D.5), i.e., each λabstraction<br />

(\x1 . . . xn->e) is replaced by the expression (let f x1 . . . xn = e in f) where<br />

f is a new function name. This transformation must be recursively applied to all λabstractions<br />

occurring in e.<br />

Eliminate Boolean guards:<br />

This is done according the meaning described in Section 2.3.2. A rule of the form<br />

f t1 . . . tn | b1 = e1<br />

.<br />

| bk = ek<br />

where decls<br />

(the where part can also be missing), where all guards b1, . . . , bk (k > 0) are expressions of<br />

type Bool, is transformed into the single rule<br />

f t1 . . . tn = if b1 then e1 else<br />

74

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

Saved successfully!

Ooh no, something went wrong!